Tell us what’s happening:
I am trying to use flat() and reduce() to solve the UniteUnique challenge.
I have an accumulator initialized to , and I’m adding each new value only if it does not already exist in the accumulator.
I keep getting the error message: TypeError: acc.contains is not a function
I also get the same message if I use acc.push(), but not acc.concat().
Any ideas what’s going on? Thanks for reading!
Your code so far
function UniteUnique(...args) {
let newarr=args.flat();
newarr = newarr.reduce((acc,curr) =>
!acc.contains(curr) ? acc.concat(curr):acc, [])
return newarr;
}
console.log(UniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 16]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
.
Challenge: Sorted Union
Link to the challenge: