Skip to content
Advertisement

Tag: recursion

Derecursing this specific JS function

I wrote the following recursive JS function that takes a single parameter node which is made of other nodes and modifies it by adding to each node its number of leaves (not only direct children) : Here’s an example of the node parameter : addWidth(object) would modify it and turn it into : I need help to make my function

Faster ‘ find & reorder’ logic in javascript

I am reordering the nodes in a certain level for a tree structure using the following recursive function. Reorder using the sort is not taking time, however recursively finding the parent node is taking time. how can I make this faster? tree data reorderedObject If i have 4 level depth and 50 items in each level, it takes 10 sec

Javascript recursion function including variables

I am trying to write a function where the function returns a sub-array of the name and age key/value pairs in the objects in an array. I am to use recursion to achieve it, however I can’t find a solution that doesn’t involve keeping the num and arr2 variables outside of the function (as when they are inside they default

How to entirely level (map / reduce / recursion) a nested object of unknown depth in the most efficient manner?

I would like to do something like the following but in a more large scale and efficient way. Assume I have an array of objects where each object needs to be leveled/flattened. Convert something like this … … to that … As is shown above, address as well is an object which needs to be leveled/flattened. But most importantly, one

Advertisement