Skip to content
Advertisement

Tag: recursion

Recursive data in JSON object

} OK guys I have such JSON structure what I need is to: return all topics in array, in this example it will be: [“SERVICE_STATUS_PRESETS”, “AIRCRAFT_ACTIVATION”, “OUT_OF_SERVICE”, “PROMO_CODES_REQUESTS”, “BANNERS”, “DOCUMENTS”, “USER”] I try recursive calls like this, though I only get last three records: Answer You could take a recursive approach and check if the handed over data is not

Return nested object with recursion – Javascript

I have an object with nested object: I need to return all key: value of list and I must use recursion. I have tried to push the nested object to the local variable in the function, but it fails in the second iteration because the names are different. Here is the function: Is there a way to solve it with

Convert array of flat objects to nested objects

I have the following array (that’s actually coming from a backend service): where Item is: In order to be compatible with a component that displays a tree (folder like) view, it needs to be transformed into: where NestedItem is: All I’ve tried so far is something like: But this only gets the first level of children, of course (direct children

How to spy on a recursive function in JavaScript

Note: I’ve seen variations of this question asked in different ways and in reference to different testing tools. I thought it would useful to have the issue and solution clearly described. My tests are written using Sinon spies for readability and will run using Jest or Jasmine (and need only minor changes to run using Mocha and Chai), but the

Javascript using Fetch and pagination, recursive?

Hello I’m new to Javascript and APIs. But I have an excersise where I should get Data from. https://swapi.co/api/planets/ The problem is that it doesn’t list all the planets at once so that URL only shows the first 10 entries while https://swapi.co/api/planets/?page=2 shows the next and so on. This is my current code, it works but I don’t think I’m

How to sum digits recursively javascript

I’m learning the basics of JavaScript and am trying to write a recursive function to add together a group of integers. For example, the function argument would be 1234 and the result should be 10. Here’s what I have so far… But I get an infinite loop whenever I run this (my tab crashes). If I’m popping the last element

Advertisement