mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-09-18 21:56:57 +02:00
18 lines
296 B
JavaScript
18 lines
296 B
JavaScript
function treeByLevels (rootNode) {
|
|
let queue = [rootNode];
|
|
let values = [];
|
|
|
|
while (queue.length > 0) {
|
|
let node = queue.shift();
|
|
if (node === null) {
|
|
continue;
|
|
}
|
|
|
|
values.push(node.value);
|
|
|
|
queue.push(node.left);
|
|
queue.push(node.right);
|
|
}
|
|
|
|
return values;
|
|
}
|