Last active
August 3, 2018 22:38
-
-
Save funador/0d1178daed38b91313b930292a0d4f4e 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 duplicates = arr => { | |
| for (let i = 0; i < arr.length; i++) { | |
| for (let j = 0; j < arr.length; j++) { | |
| // If the indexes do not match but the | |
| // values do, we have a duplicate! | |
| if (j !== i && arr[i] === arr[j]) { | |
| 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