<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Life is grand - Latest Comments in Remove array item</title><link>http://lifeisgrand.disqus.com/</link><description></description><atom:link href="https://lifeisgrand.disqus.com/remove_array_item/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 17 Jul 2006 13:46:05 -0000</lastBuildDate><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280696</link><description>&lt;p&gt;And if it doesn't have it, prototype it :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paul Watson</dc:creator><pubDate>Mon, 17 Jul 2006 13:46:05 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280695</link><description>&lt;p&gt;Andrew: Here's the JS Array Object documentation that lists what functions Array does have. As you can see, map is in there. And I think reduce is kinda like every: &lt;a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array" rel="nofollow noopener" target="_blank" title="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array"&gt;http://developer.mozilla.or...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Stone</dc:creator><pubDate>Mon, 17 Jul 2006 13:43:58 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280694</link><description>&lt;p&gt;Eek, that didn't look so good - not sure how to get  in this message board.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew Peace</dc:creator><pubDate>Sun, 16 Jul 2006 17:19:20 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280693</link><description>&lt;p&gt;The filter operation is quite cool - Python has something identical.&lt;/p&gt;&lt;p&gt;I'm not sure if javascript also has them, but a couple of other useful Python functions on sequences are map and reduce, which behave like:&lt;/p&gt;&lt;p&gt;def map(fn, list):&lt;br&gt;   newlist = []&lt;br&gt;   for item in list:&lt;br&gt;      newlist.append = fn(item)&lt;/p&gt;&lt;p&gt;def reduce(fn ,list, initial_arg = None):&lt;br&gt;   if initial_arg:&lt;br&gt;      val = initial_arg&lt;br&gt;      start = 0&lt;br&gt;   else:&lt;br&gt;      val = list[0]&lt;br&gt;      start = 1&lt;/p&gt;&lt;p&gt;   for i in range(start, len(list)):&lt;br&gt;      val = fn(val, myseq[i])&lt;br&gt;   return val&lt;/p&gt;&lt;p&gt;I may have goofed these up as I did them off the top of my head, but hopefully you get the idea.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew Peace</dc:creator><pubDate>Sun, 16 Jul 2006 17:18:29 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280692</link><description>&lt;p&gt;Better:&lt;/p&gt;&lt;p&gt;Array.prototype.remove = function(item_to_remove)&lt;br&gt;{&lt;br&gt;var index;&lt;br&gt;while((index = this.indexOf(item_to_remove)) != -1)&lt;br&gt;{&lt;br&gt;this.splice(index, 1);&lt;br&gt;}&lt;br&gt;return this;&lt;br&gt;}&lt;/p&gt;&lt;p&gt;That way you can do:&lt;/p&gt;&lt;p&gt;var filtered = [1, 2, 3, 4, 5, 6, 5, 7, 8, 5, 9, 10].remove(5);&lt;br&gt;document.write(filtered);&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Stone</dc:creator><pubDate>Fri, 14 Jul 2006 16:46:17 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280691</link><description>&lt;p&gt;Here. This:&lt;/p&gt;&lt;p&gt;Array.prototype.remove = function(item_to_remove)&lt;br&gt;{&lt;br&gt;   var index;&lt;br&gt;   while((index = this.indexOf(item_to_remove)) != -1)&lt;br&gt;   {&lt;br&gt;      this.splice(index, 1);&lt;br&gt;   }&lt;br&gt;}&lt;/p&gt;&lt;p&gt;That'll remove all of the items that match. For instance:&lt;/p&gt;&lt;p&gt;var filtered = [1, 2, 3, 4, 5, 6, 5, 7, 8, 5, 9, 10];&lt;br&gt;filtered.remove(5);&lt;br&gt;document.write(filtered);&lt;/p&gt;&lt;p&gt;1,2,3,4,6,7,8,9,10&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Stone</dc:creator><pubDate>Fri, 14 Jul 2006 16:40:42 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280690</link><description>&lt;p&gt;But is that really better than the iteration and the splice?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Stone</dc:creator><pubDate>Fri, 14 Jul 2006 15:55:17 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280689</link><description>&lt;p&gt;Ah yeah, damn, invalid assignment. Hmmmm... So it can be used outside of a prototype extension but not inside. Grr.&lt;/p&gt;&lt;p&gt;Maybe you could do this.clear and then this.push(this.filter blah blah&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paul Watson</dc:creator><pubDate>Fri, 14 Jul 2006 12:21:02 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280688</link><description>&lt;p&gt;You'd think...but setting this = this.filter... actually results in an error because you're not allowed to re-assign to this.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Stone</dc:creator><pubDate>Fri, 14 Jul 2006 12:15:17 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280687</link><description>&lt;p&gt;hhmm didn't know about Array.filter. Seems quite nice, though I wonder about performance?&lt;/p&gt;&lt;p&gt;And I reckon it could be used, just use this = this.filter(func);.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paul Watson</dc:creator><pubDate>Fri, 14 Jul 2006 04:19:02 -0000</pubDate></item><item><title>Re: Remove array item</title><link>http://paulmwatson.com/journal/2006/07/13/remove-array-item/#comment-1280686</link><description>&lt;p&gt;I'd tend to say that using the Array.filter method would be a cleaner way of doing it...but filter doesn't change the actual array, so you couldn't use that.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Stone</dc:creator><pubDate>Thu, 13 Jul 2006 17:24:24 -0000</pubDate></item></channel></rss>