Created
July 30, 2019 09:27
-
-
Save evandertino/2e05112bf5b14286a882bb5fa237c36f to your computer and use it in GitHub Desktop.
A function that given an array of integers, it return a map of integers that appear multiple times and the number of times it appears.
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 mapOfIntergers = arrayOfInts => { | |
let results = {}; | |
for (let i = 0; i < arrayOfInts.length; i++) { | |
let m = arrayOfInts[i]; | |
let count = arrayOfInts.filter(dupInt => dupInt === m).length; | |
if (count > 1) results[m] = count; | |
} | |
return results; | |
}; | |
console.log('mapOfIntergers', mapOfIntergers([1, 2, 3, 4, 6, 6, 7, 8, 9, 5, 2, 6, 1, 8])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment