The console.log of the array shows the code is working but is concluding with an error of some kind.
[ 1, 3, 2 ]
[ 1, 3, 2, 5 ]
[ 1, 3, 2, 5 ]
[ 1, 3, 2, 5 ]
[ 1, 3, 2, 5, 4 ]
[ 1, 3, 2, 5, 4 ]
TypeError: Cannot read properties of undefined (reading ‘length’)
I think it is being fidgety with arr[n].length. However, console log of arr[n].length also seems to think it is working with the right arrays.
4
4
4
4
2
2
TypeError: Cannot read properties of undefined (reading ‘length’)
**Your code so far**
function uniteUnique(...arr) {
for (let n=1; n <= arr.length; n++) {
for (let i=0; i<arr[n].length; i++){
console.log(arr[0]);
if (!(arr[n][i] in arr[0])){
arr[0].push(arr[n][i]);
}
}
}
return arr[0];
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Sorted Union
Link to the challenge: