Created
September 1, 2021 10:15
-
-
Save southbite/b6b40203012a455c375650ee5c97bea0 to your computer and use it in GitHub Desktop.
who'se your daddy algorithm, furry braaas funny PaaS
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
let organisations = [ | |
{ id: 1, name: "grandaddy", parentId: null }, | |
{ id: 2, name: "daddy", parentId: 1 }, | |
{ id: 3, name: "sister", parentId: 2 }, | |
{ id: 4, name: "brother", parentId: 2 } | |
] | |
const myChildId = 4; | |
function findChild(id) { | |
return organisations.find(org => { | |
return org.id === id; | |
}); | |
} | |
let currentChild = findChild(myChildId); | |
const breadCrumb = []; | |
while(currentChild.parentId != null) { | |
breadCrumb.unshift(currentChild); | |
currentChild = findChild(currentChild.parentId); | |
} | |
breadCrumb.unshift(currentChild); | |
console.log(breadCrumb); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment