Problem with Sorted Union Challenge

Problem with Sorted Union Challenge
0

#1

Hi, my name is Jacob and this is my first post on this forum.

I started to camp about a week ago and it’s a first time when I’ve got stucked and I don’t see light at the end of the tunnel :stuck_out_tongue:

I made some code for Sorted Union challenge and it seems to work but don’t for some reason. After i run the code I get the answer in output window which for what I can tell is correct but isn’t validated for some reason. I can only think that it is some problem with data type which i can’t see. I would be grateful if someone more experienced could look at the code and tell me where is the bug?

Code:

function uniteUnique(arr) {
arr=arguments;
var joined=[];
var unique=[];
for(var i=0;i<arr.length;i++)
{
joined=joined.concat(arr[i]);
}
var len=joined.length;
for(i=0;i<len;i++)
{
if(unique.indexOf(joined[0])===-1)
{unique.push(joined[0]);}
joined.shift();
}
return unique;
}


#2

The logic works, but it seems you can’t directly use arguments. You have to somehow transform it to a proper array.


#3

Big thanks for reply
After some investigation i discovered that indeed I need to convert arguments to real array with Array.from(arguments); method.:ok_hand: