ttomasko
Programmer
- Aug 6, 2008
- 28
Hello,
I will have two arrays of numbers. One will always be a subset of the other. What I want to know is which numbers only appear in the major set and put them in an array:
var a = [1,2,3,4,5,6];
var b = [1,2,3,6];
//result I want: [4,5]
I have tried concatenating a and b and then looking for doubles. The next step would be to delete the doubles but I can't figure out how to do that. I've also tried for statements to iterate through both arrays to find numbers that are unique in a and then push them to a new array but that does not work either.
I don't expect anyone to write the code but if you could give me a pointer or two, that would help.
I've searched the web and this exact problem does not come up except when the arrays consist of strings. I could convert the numbers to strings and use replace() to delete the doubles, then turn the string back into numbers. But that seems so inelegant.
Thanks,
Tom
I will have two arrays of numbers. One will always be a subset of the other. What I want to know is which numbers only appear in the major set and put them in an array:
var a = [1,2,3,4,5,6];
var b = [1,2,3,6];
//result I want: [4,5]
I have tried concatenating a and b and then looking for doubles. The next step would be to delete the doubles but I can't figure out how to do that. I've also tried for statements to iterate through both arrays to find numbers that are unique in a and then push them to a new array but that does not work either.
I don't expect anyone to write the code but if you could give me a pointer or two, that would help.
I've searched the web and this exact problem does not come up except when the arrays consist of strings. I could convert the numbers to strings and use replace() to delete the doubles, then turn the string back into numbers. But that seems so inelegant.
Thanks,
Tom