Skip to content

Instantly share code, notes, and snippets.

@JZLeung
Created August 18, 2020 06:44
Show Gist options
  • Save JZLeung/85a106cb90edca9f6e858c0cb1f2898d to your computer and use it in GitHub Desktop.
Save JZLeung/85a106cb90edca9f6e858c0cb1f2898d to your computer and use it in GitHub Desktop.
export const walkAndDealItems = (datas, func, key = 'children') => {
if (!func || typeof func !== 'function') return datas
const nodes = [...datas]
let node = nodes.shift()
while (node) {
func(node)
if (node[key]) {
for (const cNode of node[key]) {
nodes.push(cNode)
}
}
node = nodes.shift()
}
return datas
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment