Export Const Serialize = (data, sections = [], weeks = []) + = {
Const Getwithparentarray = (NEWARR, Parentindex =-1, parentindexobj = {}) = =
Newarr.map (item, index) + = {
if (Item.node_lev < 2) {
Let parentobj = {};
if (Parentindex >-1) {
Weeks[parentindex].push (Item.title);
Parentobj = {section:parentindex, week:index};
} else if (Item.node_lev = = = 0) {
Sections.push (Item.title);
Weeks.push ([]);
}
Return Getwithparentarray (Item.children, index, parentobj);
}
return {... item, Week:parentindex, ... parentindexobj};
});
return {
Sections
Weeks
Courses:getwithparentarray (data),
};
};
Export Const Flatten = (data, arr = []) + = {
Data.foreach (item) = {
if (item instanceof Array) {
Flatten (item, arr);
} else {
Arr.push (item);
}
});
return arr;
};
/* {
"Sections": [
"String"
],
"Weeks": [
["String"]
],
"Courses": [{
"_id": "string",
"title": "String",
"Course_type": "NORMAL",
"section": 0,
"Week": 0,
}]
} */
Algorithms for flattening data