Using array.reduce method to count duplicate elements
const alphabets = [1,1,1,2,3,3,1,4,5]; const counts = alphabets.reduce((acc, current) => { if(acc[current]){ acc[current] += 1; } else { acc[current] = 1; } return acc; }, {}); console.log(counts); //{ '1': 4, '2': 1, '3': 2, '4': 1, '5': 1 }
Algorithms
2022. 10. 23. 14:27
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Collection Framework
- hackerrank
- Object type casting
- repeat()
- substring()
- ... in Javascript
- hackerrank solution
- HashMap
- HackerRank Algorithm
- 프로그래머스 알고리즘
- string class in java
- 프로그래머스 알고리즘문제
- java
- 알고리즘
- hackerrank javascript
- equals()
- 프로그래머스
- math.max
- Javascript Algorithm
- algorithm
- compareTo()
- easy javascript algorithm
- C++
- javascript
- spring boot application
- code refactoring
- math.abs
- rest parameter
- easy algorithm
- hackerrank javascript solution
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함