Last active
August 4, 2017 12:47
-
-
Save teslitsky/c7d4087ea4a700b453998076eb478c93 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Приветствую!
Поздравляю, ваш код прошел все наши тесты.
Пожалуйста, заполните форму регистрации на курс:
https://goo.gl/BEq8sP