Yea, I believe there’s something wrong with the web. It does not even console.log primitives value in the second loop. It skips from for loop at 5, then line 16.
And when we console.log(arr) in the first line of of the function, it actually console.log the first subArray. If we console.log(arr[0]), it prints 1.
console.log("line 2")
let result = [];
console.log("line 3")
for (let i = 0; i < arr.length; i++) {
console.log("for loop at 5: " + i)
for (let j = 0; j < arr[i].length; j++) {
console.log("for loop at 7: " + j)
if (result.indexOf(arr[i][j] == -1)) {
console.log("if at 9")
console.log(result.indexOf(arr[i][j]))
result.push(arr[i][j])
console.log("line 11")
}
}
}
console.log("line 16")
return result;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
you are getting only 1st array from input stored in arr variable
you need to spread it like this uniteUnique(…arr) which allow you to access input arrays with index .
like arr[0] arr[1 ] and so on.
keep result empty array insert elements if not already exists
since array index starts with 0 you should initialize i with 0.