Write a function that takes two or more arrays and returns a
new array of unique values in the order of the original provided arrays.
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.
So what the instructions mean is that i’m suppose to take all 3 arrays and get unique values and return them in order in their original array order.
My question is, how am i suppose to get all 3 arrays if i have one parameter? Its not a 2D array and i wont know how many arrays the input is, so i cant just put 3 parameters. When i run the code listed above i get:
[1, 3, 2] (1/3 arrays)
Any ideas on how i get all 3 arrays with 1 parameter. I know you can change teh starting code, but the requirements dont use 2D arrays for there input…
What i mean by 2D arrays is all the input arrays in 1 big array so i can access all 3 at once. Am i missing something with this?
Basically, when you run a function, an arguments object is created with all of the objects that were passed to the function.
If you have a function
function foo(bar) {
return baz
}
Bar, in this case, is defined, but if you pass more than one argument into the function javascript will store that extra argument (as well as any other arguments) in what is known as an argument object.
Most people convert this argument object into an array using these lines of code (these are three different ways of converting, only one line is necessary):
var args = Array.prototype.slice.call(arguments);
var args = [].slice.call(arguments);
// ES2015
const args = Array.from(arguments)
From here you can access any arguments that were passed to the function even if you only specified one parameter.
Oh okay, I didn’t read the article at all I was just responding because from your reaction to the article it didn’t seem like your problem was solved glad you figured it out though!
I’m not really sure what you mean; however, in javascript [5] is an array with a value of 5 at index 0, 5 is a number so they are very different. If you’re ever wondering if something is the same console.log the two values with a strict equal ‘===’ in between them and if they are the same they will log true, false otherwise.
So if you sort this you need one of every number that you encounter in the order that you encountered it in. That’s what I’m gathering from the instructions.
I know that, but with [1, 3, 2], [5, 2, [3], 4], [3, 1], would i put 3 in my final array since 3 is present through the whole thing or not 3 but just [3] because one is a array and one isnt?
I don’t think the returned array is supposed to be two dimensional. As far as I’m reading it seems like you should return an array of only numbers, not an array that has another array inside of it. So if you already have 3 in your returned array not only do you not need to add an array [3] but you shouldn’t add another 3 value either.
Okay, I went and looked at the challenge and yes your array can be two dimensional. As far as your last question it looks like they just need to be unique values, not values that appear in every array.
Um, technically yes; however, you’re thinking about the wrong array. The array you return needs to have unique values. The challenge is to find values within each array and put it in another array. If the array you’re storing everything in already has the value you’re trying to store you want to skip that value.
You’ve got an array of arrays containing arbitrary values. You need to merge them into a single array and remove any duplicates. The values can be numbers or arrays. [5] is not the same as 5.