Skip to content

Instantly share code, notes, and snippets.

@JoseGonzalez321
Created May 20, 2019 13:12
Show Gist options
  • Save JoseGonzalez321/4a1a61a1de561b68038abc47e88566b2 to your computer and use it in GitHub Desktop.
Save JoseGonzalez321/4a1a61a1de561b68038abc47e88566b2 to your computer and use it in GitHub Desktop.
// 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