Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concatenate Many Arrays Uniquely With Javascript
#1
Hello Coers, i was working on a javascript function which require me to take a single parameters which will contain multiple array through a function and also ensure i uniquely merge the arrays together without repeating an element twice.

I thought this code might be of help, check it out here:


Code:
function uniqueArr(arr) {
  var take = [];
for(var i = 0; i < arguments.length; i++) {
  take.push(arguments[i]);
}
var see=  take.reduce(function(a, b) {
    return a.concat(b);
  }, []);
return see.filter(function(a,b) {
  return see.indexOf(a) === b;
});
}

uniqueArr([1, 3, 2], [5, 2, 1, 4], [2, 1]);

It takes so long to learn simplicity.
Facebook Share


Possibly Related Threads...
Thread
  Beginner Javascript Coding Mistakes To Avoid
  Javascript Time Ago Function
  Shortest Code For Random Number Between 1 And N In Javascript
  Javascript Text Editor Right In Your Browser In One Line Of Code
  Getting Current Location With Javascript
  How To Check If Javascript Object Is Empty
  How To Create An Image Slider With Javascript
  Convert Numbers To Roman Numerals With Javascript
  TUTORIAL: How To Make A Digtal Clock With Javascript
  Remove All Falsy Values From An Array With Javascript




Users browsing this thread: 1 Guest(s)