Created
July 12, 2018 08:46
-
-
Save ck3g/9293d01ae2914481ef8b6a2c3e457ed3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
people = [{name: 'Alice'}, {name: 'Bob'}, {name: 'Bill'}, {name: 'Alex'}, {name: 'John'}]; | |
people.reduce((obj, person) => { | |
const firstLetter = person.name[0].toUpperCase(); | |
return { | |
...obj, | |
[firstLetter]: [...(obj[firstLetter] || []), person] | |
} | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment