Complete the code to initialize the result variable to zero.
let result = [1];We start with zero because XOR with zero returns the other number unchanged.
Complete the for loop to iterate over all elements in the array 'arr'.
for (let i = 0; i [1] arr.length; i++) { result ^= arr[i]; }
The loop should run while i is less than arr.length to avoid out-of-bounds access.
Fix the error in the XOR operation inside the loop.
result [1] arr[i];The XOR assignment operator '^=' is used to combine bits correctly.
Fill both blanks to complete the function signature and return statement.
function findUnique(arr: number[]): number {
let result = 0;
for (let i = 0; i < arr.length; i++) {
result [1] arr[i];
}
return [2];
}Use '^=' to XOR each element with result, then return result.
Fill all three blanks to complete the code that calls the function and prints the unique element.
const numbers = [2, 3, 5, 4, 5, 3, 4]; const unique = [1](numbers); console.[2]("Unique element is:", [3]);
Call findUnique with numbers, then log the unique variable to console.
