I’ve written a recursive function to find a given object and the path within that tree, but when I change the target id (over here : if(tree.targetModuleId === 7)) to 10 I got error: “message”: “Uncaught TypeError: Cannot read properties of undefined (reading ‘unshift’)” I supposed to get the path: [1,2,5,6,10]. In the end I need the option that no
Tag: recursion
how to get an updated copy of a node tree after removing some of its nodes?
I need based on a condition to remove a node from a tree nodes and obtain as a result an updated copy of the tree nodes With the help of this answer https://stackoverflow.com/a/72121755/615274 I get to the node to delete, I exclude it from the array it belongs to but the returned node tree does not reflect the changes The
How to filter array of nested objects with unknown depth based on given search term
There are similar answers here but all of the ones I’ve seen and tested don’t go pass two levels deep, so I don’t think this is a duplicate problem…I am trying to filter an array of objects. Each of its objects can have other nested objects of unknown depth. For my data, treeView is a collection of treeData, and treeNode(children)
question regarding max value in an array with recursion in JavaScript
Currently, I was able to get the following function to retreive the max value from an array through recursion However, when I try to refactor it with an extra parameter “b” through destructuring, the whole function just won’t work properly anymore. Can someone kindly explain what I am doing wrong or point me in the right direction. I am new
How can I mimic a Javascript “spread operator” in C#?
I am following a tutorial on Dynamic Programming on youtube to understand more about Recursive functions, and I am stuck where a spread operator is used. Code in JavaScript This is the code in C# where I’m trying to replicate the function EDIT: Should I use a Dictionary and use a key? I don’t understand how to work my way
Recursively filter an array of infinitely nested objects by mutliple matching conditions but only return parent that has an instance of both matches
I have the following array of objects; however this could be any unknown key/value and be infinitely nested, for now this is a testing sample: My current implementation is as follows: Basically I am adding to the “selected” array then using that to filter the data array by. I do want to ensure the key matches the “column” also however
how to sort recursively in JS
I’m trying to sort an Array type data recursively. Here’s the data structure. I wanna sort by either ‘id’ or ‘name’. This is what I tried. In my poor logic, it seems working but not properly working. Because item’s children or children’s children is not sorted. 🙁 What should I fix? or maybe my approach was totally wrong? Thank you
Javascript recursive with for loop breaks the loop and does not finishes
I am writing a recursive function that needs to run in an array of objects with any level of deepness. (if it finds an array it will run into this array after finishing the object properties) The idea is to create a generic table in a webpage that can handle any king of object structure and rendering elements respecting their
Javascript array recursion question – looping through “sections”
I’m strugguling with Javascript on how to find all combinations of an array source with n depth that is broken into sections (0, 1, & 2 in example below). I want to end up with each possible cominbation – and each returned array should include one and only one value from each group. I’ve hardcoded a solution to 4 levels,
Memoize a recursive Fibonacci function
I created a withMemo function that returns a memoized version of the provided function. How can I memoize this fibonacci function that works with recursion ? Indeed withMemo(fibo) doesn’t improve performance since the recursive calls inside fibo still point to the unmemoized version… So I have to alter the declaration of fibo to make momoization work: Is there a way