<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'Remove Duplicate Values from Array'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Thu, 20 Jun 2013 08:38:23 GMT</pubDate>
<item>
<title>malachaifrazier said on 11/9/12</title>
<link>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</link>
<description><![CDATA[ Well done! 
I just implemented this in Coffeescript:
<code>$ ->
	unique = (origArr) ->
	  newArr = []
	  origLen = origArr.length
	  found = undefined
	  x = 0
	  y = 0
	  x = 0
	  while x < origLen
	    found = `undefined`
	    y = 0
	    while y < newArr.length
	      found = true  if origArr[x] is newArr[y]
	      y++
	    newArr.push origArr[x]  unless found
	    x++
	  newArr </code> ]]></description>
<pubDate>Fri, 09 Nov 2012 12:55:42 GMT</pubDate>
<guid>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</guid>
</item>
<item>
<title>dvdrtrgn said on 12/14/10</title>
<link>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</link>
<description><![CDATA[ Let's golf:

`function unique(arr,dup) {
    dup = dup ? arr.concat() : arr;
    for (var i=0; i < dup.length; i++) 
        if (dup.indexOf(dup[i]) < i) dup.splice(i--);
    return dup;
}` ]]></description>
<pubDate>Tue, 14 Dec 2010 16:29:31 GMT</pubDate>
<guid>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</guid>
</item>
<item>
<title>ronydee said on 12/12/10</title>
<link>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</link>
<description><![CDATA[ this function extends the Array object and cleans the duplicates from the input Array instead of creating a new one:

Array.prototype.unique = function unique()
{
	var i = 0;
	while (i < this.length)
	{
		var current = this[i];
		for (k = this.length; k > i; k--)
		{
			if (this[k] === current)
			{
				this.splice(k,1);
			}
		}
		i++;
	}
	return this;
}

var myarray = ['jeffrey', 'allie', 'patty', 'damon', 'zach', 'jeffrey', 'allie', 'patty', 'damon', 'zach', 'joe'];
alert(myarray.unique().join(', ')); ]]></description>
<pubDate>Sun, 12 Dec 2010 04:24:28 GMT</pubDate>
<guid>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</guid>
</item>
<item>
<title>AlexWolfe said on 12/7/10</title>
<link>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</link>
<description><![CDATA[ Oops, scratch that. I read the code wrong. Sorry, !found definitely makes more sense because you are trying to avoid duplicates. ]]></description>
<pubDate>Tue, 07 Dec 2010 15:00:24 GMT</pubDate>
<guid>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</guid>
</item>
<item>
<title>AlexWolfe said on 12/7/10</title>
<link>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</link>
<description><![CDATA[ Would it be nice to set found = false; That way you could say if(found) newArr.push instead of if(!found). Both work, just seems like it would be more elegant.

 Also, I'm not a big fan of setting vars to undefined. If you set a variable to undefined because if you don't even declare a var its returns undefined. ]]></description>
<pubDate>Tue, 07 Dec 2010 14:52:47 GMT</pubDate>
<guid>http://snipplr.com/view/45323/remove-duplicate-values-from-array/</guid>
</item>
</channel>
</rss>