Last active
August 3, 2018 22:31
-
-
Save funador/edc51bf3dc946a91739bec9519ecc3d1 to your computer and use it in GitHub Desktop.
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 nums = [2, 6, 3, 10] | |
const nums2 = [2, 4, 1, 2] | |
const duplicates3 = arr => { | |
for (let i = 0; i < arr.length; i++) { | |
const num = arr[i] | |
// We take a slice of the remaining Array | |
// and see if that includes the num | |
// it must be a duplicate | |
if(arr.slice(i + 1).includes(num)) { | |
return true | |
} | |
} | |
// We looked at everything and no matches! | |
// There are no duplicates | |
return false | |
} | |
console.log(duplicates3(nums)) // false | |
console.log(duplicates3(nums2)) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment