The Duplicate Echo

MediumAcc. 92.5%
+30 XP 12

Identifying Shadows

A duplicate exists if any two different indices contain the same value.

The Assignment

Your function receives an array data.

  1. Initialize a variable hasDuplicates to false.
  2. Use a nested loop structure:
    • The outer loop runs with index i.
    • The inner loop runs with index j, starting from i + 1.
  3. If data[i] === data[j], set hasDuplicates to true and exit both loops.
  4. Print the final value of hasDuplicates.

01EXAMPLE 1

Inputdata = [5, 8, 2, 5, 9]
Outputtrue

Explanation: 5 is repeated.

Constraints

  • Do not use the Set object.
  • Use nested for loops (i and j).
ArraysLoopsLogic
JavaScript
Loading...
2 Hidden

Input Arguments

data[5,8,2,5,9]

Expected Output

true

Click RUN to test your solution