Comment on Stupid LanguagesComments−ricardobeat13yI think one of the reasons for the third argument (the array itself) is to permit chaining. Consider this: var publishedPosts = posts.filter(function(post){ return post.published }) var intervals = publishedPosts.map(function(post, i){ var next = publishedPosts[i+1] return post.date - (next && next.date || 0) }) With the array reference you don't need an intermediate var: var intervals = posts.filter(function(post){ return post.published }).map(function(post, i, arr){ var next = arr[i+1] return post.date - (next && next.date || 0) })−krickle13yI think in that case it would be better to make it variadic on input arrays, like map(makeInterval, array, array.tail())
Comments
I think one of the reasons for the third argument (the array itself) is to permit chaining. Consider this:
With the array reference you don't need an intermediate var:I think in that case it would be better to make it variadic on input arrays, like map(makeInterval, array, array.tail())