Created
September 13, 2021 16:59
-
-
Save onurinanc/7923a8dffcc0bf09c6f8007c301c450d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const apples = ['green', 'red', 'red', 'yellow', 'red', 'yellow', 'green', 'green']; | |
| var appleMap = apples.reduce((prev, apple) => { | |
| if (prev[apple] >= 1) prev[apple]++; | |
| else prev[apple] = 1; | |
| return prev; | |
| }, {}); | |
| console.log(appleMap); | |
| // result: {green: 3, red: 3, yellow: 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment