Help with de problem "Sorted Union"

Cuéntanos qué está pasando:

Hi!.
Why this code doesn’t work well with the property .hasOwnProperty()
at the third argument[0] is the problem, just works well from 1 to 4, apart from there doesn’t work.

  **Tu código hasta el momento**

function uniteUnique(arr) {

let args = [];
let newArr = [];
for (let i = 0; i < arguments.length; i++) {
  args.push(arguments[i]);
}
args.map(x => {
  x.map(z => {
    if(!newArr.hasOwnProperty(z)){
      newArr.push(z);
    }
  })
})
console.log(newArr)
return newArr;
}

uniteUnique([1, 2, 3], [5, 2, 1, 4], [5, 1], [6, 7, 8]);

Enlaza al desafío:

hasOwnProperty() isn’t intended to be used with arrays like this.


Side note, that is the wrong way to use a map. A map is for making a new array out of an old array by transforming the elements of the old array. A map is not a generic way to loop over an array.

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