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.
[-] The following 1 user Likes Dealwap's post:
  • Horlahcoded


Possibly Related Threads...
Thread Author Replies Views Last Post
  SHARED: Introducing Hrouter.js Javascript Routing Library Horlahcoded 7 84 10-16-2017, 10:13 PM
Last Post: iamdannyfc
  SHARED: Introducing Hkwest.js Javascript Ajax Library Horlahcoded 0 37 10-15-2017, 09:46 AM
Last Post: Horlahcoded
  HELP: Javascript Vs Jquery. beme 10 296 08-21-2017, 07:20 AM
Last Post: beme
  Test Your Javascript Knowledge Dealwap 10 563 08-16-2017, 07:41 PM
Last Post: Thepreditor
  How Can I Submit A Form Using Javascript iamdannyfc 11 235 06-22-2017, 10:13 PM
Last Post: bfaschat
  TUTORIAL: Take A Selfie With Javascript SamBlingxZ 0 82 06-05-2017, 11:41 PM
Last Post: SamBlingxZ
  3 Types Of Javascript Animations That I So Much Admire! Laive 5 213 05-20-2017, 09:40 AM
Last Post: Laive
  HELP: How Can I Create A Javascript Ads Rotator For My Site Eddykul 5 219 03-30-2017, 09:51 AM
Last Post: Harsh
  Beginner Javascript Coding Mistakes To Avoid smartlord 2 257 02-08-2017, 04:04 PM
Last Post: smartlord
  Javascript Time Ago Function Dealwap 2 216 01-03-2017, 11:54 AM
Last Post: Aphatheology



Users browsing this thread: 1 Guest(s)

About Nigeria's Creative Talents

Nigeria's Creative Talents is an online community where every creative Nigerians can share ideas with themselves.

For any more information, please use our contact form.

              User Links

              Advertise