Just finished doing the Sorted Union Challenge. I got through it with a few for loops, but I feel like theres a more effective way i could have gotten the same results using methods and using less code… any ideas?
function uniteUnique(arr) {
var newArr = [];
// push first array to newArr
for (var i=0;i<arguments[0].length;i++) {
newArr.push(arguments[0][i]);
}
//compare new arr to next arrys, push the values that are not already in newArr
//loop over arguments arrays
for (var j = 1;j<arguments.length;j++) {
//loop over individual arrays
for (var k = 0;k<arguments[j].length;k++) {
if (newArr.indexOf(arguments[j][k]) === -1) {
newArr.push(arguments[j][k]);
}
}
}
return newArr;
}