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.
- Initialize a variable
hasDuplicatesto false. - Use a nested loop structure:
- The outer loop runs with index
i. - The inner loop runs with index
j, starting fromi + 1.
- The outer loop runs with index
- If
data[i] === data[j], sethasDuplicatesto true and exit both loops. - Print the final value of
hasDuplicates.
01EXAMPLE 1
Input
data = [5, 8, 2, 5, 9]Output
trueExplanation: 5 is repeated.
Constraints
- Do not use the Set object.
- Use nested for loops (i and j).
ArraysLoopsLogic
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
data[5,8,2,5,9]
Expected Output
true
Click RUN to test your solution