April 6th, 2024
What's missing in this code?
// Check if array has sub-array of 3 items
// where the 1st and 3rd are the same but
// both different from the 2nd, e.g., [1, 2, 1]
// hasBoomerang([3, 6, 3, 6, 1]); // true - [3, 6, 3]
// hasBoomerang([3, 1, 1, 6, 7]); // false
// hasBoomerang([5, 4, 7, 0, 7]); // true - [7, 0, 7]
// hasBoomerang([2, 0, 3, 3, 3]); // false
function hasBoomerang(arr)
const pair = [];
for (const num of arr)
pair.push(num);
if (pair
=== 3)
const [a, b, c] = pair;
if (
)
return true;
}
pair.
;
}
}
return false;
}
Type or select from these options