Help me understand how I broke the includes() method

Help me understand how I broke the includes() method

I’m not necessarily looking for an answer to the challenge, but to understand how I seem to have broken the includes() method.

Following is a link to a codepen where I’m trying to solve the intermediate algorithm scripting Sorted Union challenge.

There is a line towards the end in an else statement that when uncommented seems to break the includes method. With that line I’m trying to manipulate an array that I’m performing the includes method on.

Like I said I’m not looking for a solution to the challenge, if I want to that is easy enough. I want to understand why a method doesn’t work in a particular case.

@DZamora54 You should research the value that the push method returns. Once you discover what value gets returned from the push method, you will understand why you can not use the includes method on unitedUnique in that line.

1 Like

mistake is in your commented line.
your commented line should be unitedUnique.push(isUnique); not unitedUnique=unitedUnique.push(isUnique);
try it will solve your problem.

1 Like

push returns the new length. Now I see what was happening. Thanks.