Two problems of array reduce in js to solve

1. Three arrays
[1Jing 2 code 3], [4 Jing 5], [6 Jing 7]
expands into
145147156157246

2. Array objects
[{name:"a",children: [{name:"a-1"}]}, {name:"b",children: [{name:"b-1"}]}]
expand to
[{name:"a"}, {name:"a-1"}, {name:"b-1"}]

Apr.07,2021

the first one on GitHub seems to have the same function (nothing to do with reduce , but the logic is the same): https://github.com/Jiasm/note.

the second operation looks like this, if you have to use reduce :

const a = (1, 2, 3, 4, 5) // a === 5

so what your code means is to put the element in an array and then return the array, and you can simply understand that line of expression as code like this:

results.push(XXX)
return results
Menu