Last active
August 4, 2017 18:10
-
-
Save AMashoshyna/a94fbb4ace84a89299274af1c7746074 to your computer and use it in GitHub Desktop.
jsninja-test-task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawNestedSetsTree(data, node) { | |
let root = document.createElement('ul') | |
let orderedData = data.sort((a, b) => a.left - b.left) | |
orderedData.forEach(node => { | |
let newLeaf = document.createElement('li') | |
newLeaf.innerHTML = node.title | |
if((node.right - node.left) > 1) { | |
let leaves = orderedData.filter(item => item.left > node.left && item.right < node.right) | |
orderedData.splice(0, leaves.length) | |
drawNestedSetsTree(leaves, newLeaf) | |
} | |
root.appendChild(newLeaf) | |
}) | |
node.appendChild(root) | |
} | |
if (typeof module !== 'undefined') { | |
module.exports = drawNestedSetsTree; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Приветствую!
Поздравляю, ваш код прошел все наши тесты.
Пожалуйста, заполните форму регистрации на курс:
https://goo.gl/BEq8sP