Last active
August 16, 2017 22:19
-
-
Save Woodsphreaker/6bd7258ce22247a89ad4057d1609272c to your computer and use it in GitHub Desktop.
countDuplicateArrayValues
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 groupSame = (acc, el) => { | |
acc[el] | |
? acc[el]++ | |
: acc[el] = 1 | |
return acc | |
} | |
const groupDuplicate = (list) => list.reduce(groupSame, {}) | |
const findDuplicate = (el) => groupDuplicate([...el]) | |
console.log(findDuplicate('Aliquam in erat dui. Mauris pellentesque leo at velit faucibus tincidunt non id eros.')) | |
/* | |
{ A: 1, | |
l: 5, | |
i: 9, | |
q: 2, | |
u: 7, | |
a: 5, | |
m: 1, | |
' ': 13, | |
n: 6, | |
e: 8, | |
r: 3, | |
t: 6, | |
d: 3, | |
'.': 2, | |
M: 1, | |
s: 4, | |
p: 1, | |
o: 3, | |
v: 1, | |
f: 1, | |
c: 2, | |
b: 1 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment