Skip to content

Instantly share code, notes, and snippets.

@teslitsky
Last active August 4, 2017 12:47
Show Gist options
  • Select an option

  • Save teslitsky/c7d4087ea4a700b453998076eb478c93 to your computer and use it in GitHub Desktop.

Select an option

Save teslitsky/c7d4087ea4a700b453998076eb478c93 to your computer and use it in GitHub Desktop.
function drawNestedSetsTree(data, node) {
if (!data || !data.length) {
return false;
}
const ul = document.createElement('ul');
data.sort((a, b) => (a.left - b.left));
data.forEach((item) => {
if (!item.title) {
return false;
}
const li = document.createElement('li');
li.textContent = item.title;
if (item.left + 1 === item.right) {
ul.appendChild(li);
} else {
const nodes = data.filter((el) => el.left > item.left && el.right < item.right);
data.splice(0, nodes.length);
drawNestedSetsTree(nodes, li);
ul.appendChild(li);
}
});
node.appendChild(ul);
}
if (typeof module !== 'undefined') {
module.exports = drawNestedSetsTree;
}
@jsninjabot
Copy link

Приветствую!
Поздравляю, ваш код прошел все наши тесты.
Пожалуйста, заполните форму регистрации на курс:
https://goo.gl/BEq8sP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment