Problem using reduce in UniteUnique challenge

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:

contains is for html nodes

You may want to use includes


If you are ever in doubt about what prototype methods are on something you can open up the browser console and look at the autocomplete you get.


Or you can always go MDN and check.

1 Like

Thank you! For some reason I get them confused and then I don’t notice.

I figured out the other one as well – push returns the length, rather than an array.

Thank you! That’s a great shortcut.