Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created February 26, 2019 19:31
Show Gist options
  • Save andrIvash/af0a28b0769868faaadba44f831c3564 to your computer and use it in GitHub Desktop.
Save andrIvash/af0a28b0769868faaadba44f831c3564 to your computer and use it in GitHub Desktop.
linkedList
const linkedList = {
toc: {
children: [
{id: '1-1', val: '1-1', children: []},
{
id: '1-2',
val: '1-2',
children: [
{id: '2-1', val: '2-1', children: []},
{id: '2-2', val: '2-2', children: []},
{id: '2-3', val: '2-3', children: []},
{
id: '2-4',
val: '2-4',
children: [
{id: '3-1', val: '3-1', children: []},
{
id: '3-2',
val: '3-2',
children: [
{id: '4-1', val: '4-1', children: []},
{id: '4-2', val: '4-2', children: []},
{id: '4-3', val: '4-3', children: []},
{
id: '4-4',
val: '4-4',
children: [
{id: '5-1', val: '5-1', children: []},
{id: '5-2', val: '5-2', children: []},
{id: '5-3', val: '5-3', children: []},
]
}
]
}
]
}
]
}
]
}
};
var res = [];
function seeker (arr) {
arr.forEach(function(elem){
if(elem.children.length) {
res = elem.children.slice();
seeker(elem.children);
}
})
}
seeker(linkedList.toc.children);
console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment