Created
May 20, 2019 13:12
-
-
Save JoseGonzalez321/4a1a61a1de561b68038abc47e88566b2 to your computer and use it in GitHub Desktop.
This file contains 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
// find duplicate primitive elements in an array (e.g. array of ints) | |
function findDuplicates(data) { | |
let result = []; | |
data.forEach(function(element, index) { | |
// Find if there is a duplicate or not | |
if (data.includes(element, index + 1)) { | |
// Find if the element is already in the result array or not | |
if (!result.includes(element)) { | |
result.push(element); | |
} | |
} | |
}); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment