Saturday, November 12, 2011
My Favorite Javascript Method for Removing Array Duplicates
var dedup = function(a)
{
var b = [], //create a replacement array
i=a.sort().length; //get the dups together
while(i--) //loop down the original array
{
// they are bunched, so copy only non matches
if(a[i]!==a[i-1])
{
b[b.length] = a[i];
}
}
return b; // return the replacement array
}
// test it
console.log('Original Array: bob,sally,9,sally,george,george,andrew,23,230,\'23\'\n' + 'Deduped Array:'+ dedup(['bob','sally',9,'sally','george','george','andrew',23,230,'23']));
Subscribe to:
Post Comments (Atom)
Founded in 2000, its major site, tombola.co.uk has turn into the biggest bingo website in the UK, with more gamers than any other company, properly as|in addition to} being number one in Spain and Italy. BETER Live is the live-casino brand of next-gen betting content material and data supplier BETER, whose different product verticals include quick sports activities, esports and gaming 바카라사이트 options. This fun-filled sport combines the thrills of each lotto and bingo, in a single fun-fuelled expertise. You can choose to bet with very small stakes and watch because the ball slides round, in hope of your profitable numbers lining up. There are some huge bonuses on offer, and if you win, find a way to|you possibly can} choose to extend the quantity with a variety of multipliers.
ReplyDelete