News for hackers. Stuff that matters.
Re:How to use array reduce for more than just numbers by runarberg on Sunday June 02, 2019 @12:07PM (#20076285)
You can also use `.map()` and `Object.fromEntries` if you really don’t want to mutate the accumulator:

    function keyByUsername(person) {
      return [person.username, person];
    }

    const peopleObj = Object.fromEntries(peopleArr.map(keyByUsername));
But you should probably be using a `Map` for this anyway:

    const peopleMap = new Map(peopleArr.map(keyByUsername));

There are no comments on this comment yet.