DEV Community

Francesito
Francesito

Posted on

Solved 'Ordered union' / FreeCodeCamp Algorithm

function uniteUnique(arr) {
  let arrNumbers = [];
  let newArray = [];
  for(let i=0;i<arguments.length;i++){
    for(let j=0;j<arguments[i].length;j++){
    arrNumbers.push(arguments[i][j]);
    }
  }
  for(let i=0;i<arrNumbers.length;i++){
     (newArray.indexOf(arrNumbers[i]) == -1) ?
      newArray.push(arrNumbers[i]) : false;
    }
  return newArray;
}
console.log(uniteUnique([1, 3, 2, 3], [5, 2, 1, 4], [2, 1]));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)