Skip to content

Instantly share code, notes, and snippets.

@pauloportella
Created August 22, 2018 16:09
Show Gist options
  • Save pauloportella/10d44755119d5a0d343ac95fc9447bfe to your computer and use it in GitHub Desktop.
Save pauloportella/10d44755119d5a0d343ac95fc9447bfe to your computer and use it in GitHub Desktop.
containsDuplicates = a => a.length > new Set(a).size
Given an array of integers, write a function that determines whether the array contains any duplicates. Your function should return true if any element appears at least twice in the array, and it should return false if every element is distinct.
Example
For a = [1, 2, 3, 1], the output should be
containsDuplicates(a) = true.
There are two 1s in the given array.
For a = [3, 1], the output should be
containsDuplicates(a) = false.
The given array contains no duplicates.
Input/Output
[execution time limit] 4 seconds (js)
[input] array.integer a
Guaranteed constraints:
0 ≤ a.length ≤ 105,
-2 · 109 ≤ a[i] ≤ 2 · 109.
[output] boolean
[JavaScript (ES6)] Syntax Tips
// Prints help message to the console
// Returns a string
function helloWorld(name) {
console.log("This prints to the console when you Run Tests");
return "Hello, " + name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment