by Pawan Kumar @jsartisan
Given an array of integers nums
, write a function that returns true
if any value appears at least twice in the array, and returns false
if every element is distinct.
Requirements:
- The function should take one argument:
- An array of integers,
nums
.
- An array of integers,
- The function should return:
true
if there is at least one duplicate value.false
if all values are unique.
Example Usage:
// Example 1
const nums1 = [1, 2, 3, 3];
console.log(hasDuplicate(nums1)); // Output: true
// Example 2
const nums2 = [1, 2, 3, 4];
console.log(hasDuplicate(nums2)); // Output: false