Questions tagged [Recursion] (82)

1
answer

What I missed, when dealing with recursion?

there is such an array const dataArr = [ { "id": 28, "title": "Free content", "children": [ { "id": 29, "title": "Lorem", "children": [ { "id": 32, "title": "Lorem", "children": [] }, { "id": 30, "title": "Lorem", "children": [] } ], }, { "id": 33, "title": "Lorem", "children": [ { "id": 35, "title": ...
alfreda_Dibbert asked April 19th 20 at 12:32
2
answers

How to get the array of keys of a nested object, you can get a known value?

const obj = {'a': {'b': 1, 'c': 2, 'd': {...}, ...}, ....}; const keys = find(obj, 1); // ['a', 'b']
billy_Johns asked April 8th 20 at 18:24
1
answer

How to do recursion in this case?

There is an array of var products = [ { name: 'pac1', packingLevel: 1, childItems: [ { name: 'prod1', packingLevel: 0, }, { name: 'prod2', packingLevel: 0, } ] }, { name: 'pac2', packingLevel: 2, childItems: [ { name: 'upac1', packingLevel: 1, childItems: [ { name: 'prod01', packingLevel: 0, }, { name: 'pr...
emmet.Goldner asked April 8th 20 at 09:20
2
answers

How to make a recursive sequential async-await?

Need sequentially to perform a series of asynchronous requests and the data push to an array. The source data has a tree structure: let data = [{ url: '/some-url', children: [ { url: 'some-url', children: null }, { url: 'some-url', children: [ url: 'some-url', children: null ] } ] }, { url: 'some-url', children: ...
Lon.Johnston98 asked April 8th 20 at 02:04
1
answer

How to find recursively the object or array by key and value?

/** * @param {array|Object}searchInArray * @param {string|int} searchKey * @param {string|int} searchValue * * @todo - use lodash? * * @return {Object} */ function walkRecursive ({searchInArray, searchKey, searchValue}) { let returnValue = {}; if (false === Array.isArray(searchInArray)) { searchInArray = Object.keys...
Reva_Mann asked April 7th 20 at 11:24
1
answer

As recursively to assign to array keys the value of one of its fields?

Need recursively the keys to make the value of the field id in the array if it is. Original structure: spoiler$arr = [ [ 'id' => 1, 'name' => 'Brand 1', 'cities' => [ [ 'id' => 16, 'name' => 'Moscow', 'shops' => [ [ 'id' => 35, 'name' => 'Store 35' ], [ 'id' => 42, 'name' => 'Shop 6...
wyman asked April 4th 20 at 14:08
2
answers

Why recursion is not working?

Knead the bread on codewars. Please tell me (hint) where I made a mistake, though the line number. Think he will sit. digital_root function(n) { let res = []; function getResult(num) { let result = num.toString().split(").reduce((sum, current) => { let count = +sum + +current; if(count.length > 1) getResul...
Patricia_Murphy asked April 4th 20 at 13:16
1
answer

How to recursively generate a list of ul?

Need of n dimensional array to generate a ul list, I've poked this code but the process has stalled - maybe someone with fresh eyes to tell how to do? In fact the structure as follows: [ { "id": 1, "parent_id": null, "children": [ { "id": 2, "parent_id": 1, "children": [] }, { "id": 3, "parent_id": 1, "children":...
greta.Oberbrunner asked April 4th 20 at 13:11
2
answers

How to write a recursive function in PostgreSQL?

How to write a recursive function? The function is supplied the id of the film and the result displays all the prequels for the film. spoiler Here is my version of the function, but it displays all the movies. spoilercreate or replace function get_all_prequils(filmid int) returns table (id int, filmname varchar prequelid i...
Peter_Goodwin asked April 4th 20 at 12:59
2
answers

Why recursion persists?

Task Butterscotch weighs X grams, tangerine – Y gram, the carrot – Z grams. Need to write a program that determines how many different options of gifts weight exactly W grams can make Santa Claus. Input The only line of the input file INPUT.TXT contains four integers X, Y, Z and W (1 ≤ X, Y, Z ≤ 100, 1 ≤ W ≤ 1000). Output T...
westley_Rice asked April 4th 20 at 12:45