Skip to content

Instantly share code, notes, and snippets.

@arackaf
Created December 22, 2015 19:20
Show Gist options
  • Save arackaf/f14fdcbacd2fa3b11603 to your computer and use it in GitHub Desktop.
Save arackaf/f14fdcbacd2fa3b11603 to your computer and use it in GitHub Desktop.
function stackAndGetTopLevelSubjects(subjects){
subjects.forEach(s => {
s.children = [];
s.children.push(...subjects.filter(sc => new RegExp(`,${s._id},$`).test(sc.path)));
});
return subjects.filter(s => s.path == null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment