Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Last active August 16, 2017 22:19
Show Gist options
  • Save Woodsphreaker/6bd7258ce22247a89ad4057d1609272c to your computer and use it in GitHub Desktop.
Save Woodsphreaker/6bd7258ce22247a89ad4057d1609272c to your computer and use it in GitHub Desktop.
countDuplicateArrayValues
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