Tell us what’s happening:
Solution 3 could be a little bit confusing: filter doesn’t filter the first subarray so the “unique” criteria applied by this function is not consistent with “a function that takes two or more arrays and returns a new array of unique values”. For example:
function uniteUnique(arr) {
var newArr;
var args = Array.prototype.slice.call(arguments);
newArr = args.reduce(function(arrA, arrB) {
return arrA.concat(
arrB.filter(function(i) {
return arrA.indexOf(i) === -1;
})
);
});
return newArr;
}
uniteUnique([1, 1, 1], [5, 2, 1, 4], [2, 1]); //-> [ 1, 1, 1, 5, 2, 4 ]
Other solutions produce bullet proof results.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36 OPR/67.0.3575.115
.
Challenge: Sorted Union
Link to the challenge: