Is there anything wrong

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function uniteUnique(arr) {
let result=arr[0];
for (let i=1; i<arr.length;i++){ 
  for(let j=0;j<arr[i].length;j++){
    if (result.indexOf(arr[i][j])==-1){
return result;

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/96.0.4664.45 Safari/537.36

Challenge: Sorted Union

Link to the challenge:

result is being assigned to a number not an array so you cant push into it

uniteUnique is not called with an array of arrays, but is rather being called with multiple arguments that are arrays

There are two ways around this:

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("line 11")
  console.log("line 16")
  return result;

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
  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.

  2. keep result empty array insert elements if not already exists

  3. since array index starts with 0 you should initialize i with 0.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.