← All problemsExample 1 Example 2 Example 3
Problem
Count Duplicate Array Members
Medium- arrays
- hash-table
Return an object that maps each value appearing more than once in arr to the number of times it appears. Values that appear only once are left out.
- Input
arr = [1, 2, 2, 3, 3, 3, 4]- Output
{ 2: 2, 3: 3 }- Explanation
2 appears twice and 3 appears three times. 1 and 4 appear once.
- Input
arr = [5, 5, 5, 5]- Output
{ 5: 4 }- Explanation
a single value can be the whole result.
- Input
arr = ["a", "b", "a", "c", "b", "b"]- Output
{ a: 2, b: 3 }- Explanation
the values can be text as well.
"c"appears once, so it is left out.
Tab indents. Press Esc, then Tab to leave the editor.
Ctrl or ⌘ + Enter runs the tests.
Run your code to see every test here. Nothing is submitted or recorded.