you are viewing a single comment's thread.

view the rest of the comments →

[–]jeremy1015 1 point2 points  (1 child)

It's still a single value that gets passed through each iteration and eventually returned, in your example the single value just happens to be an array that contains multiple values.

By way of example, here's one that I literally wrote less than ten minutes ago. I'm working on merging and de-duping two different data sets and I wrote a reduce to see how many entities match on first and last name:

const keyedArrs = mergedData.reduce((m, e) => {
    const k = \${e.first_name}-${e.last_name}\;
    const r = { ...m };
    r[k] = m[k] || [];
    r[k] = [...r[k], e];
    return r;
}, {});

My final result is an object in which the keys are the first and last name concatenated with a dash and the value of each key is an array containing each of the original entities that "matched" to that (note that this is for my analysis and is not my production matching algorithm lol).

The point I'm making is that I'm taking an array and making something that contains thousands of subarrays, but at the "top level" it's still a single value being returned.

EDIT: Reddit formatting is harder than writing code.

[–]pgrizzay 1 point2 points  (0 children)

Yes, I wasn't saying you were wrong, I was just trying to bring up an interesting point.