function artistsCorrect(artistsList, photosList, camerasList) { return artists.map((artist, index) => { const extraValues = { photo: photosList[index], camera: camerasList[index] } return Object.assign({}, artist, extraValues) }) }
From imperative to functional JavaScript
Diogo Spínola
8169

I feel like you haven’t really rid yourself of the imperative thinking mindset here. The map here is essentially a for-loop without the explicit index management. That’s good, but I think you can easily go further and make this even nicer to read. A common task in the functional programming paradigm (like you’re doing here) is to merge some lists together. It’s so common that there are helpers for it widely available, in this case there’s one in lodash https://lodash.com/docs/3.10.1#zipWith. You can use it to make this a one-liner: `_.zipWith([artists, photos, cameras], (artist, photo, camera) => ({ …artist, photo, camera }))`.