Skip to content

Instantly share code, notes, and snippets.

View bakhti-ai's full-sized avatar
🙂
Practicing

Bakhtiyor Sulaymonov bakhti-ai

🙂
Practicing
View GitHub Profile
@psandeepunni
psandeepunni / flatten.js
Last active November 18, 2021 22:08
Javascript function to flatten a nested Associative Array (tree) to a List
var bfs = function(tree, key, collection) {
if (!tree[key] || tree[key].length === 0) return;
for (var i=0; i < tree[key].length; i++) {
var child = tree[key][i]
collection[child.id] = child;
bfs(child, key, collection);
}
return;
}