No idea whether this has been discussed before, but I find myself
continuously doing this when sorting arrays with objects:
arr.sort(function(a,b){ if (a.prop b.prop) return -1; if (a.prop
b.prop) return 1; return 0; });
Couldn't we add an optional string argument to Array#sort that does
this
Peter van der Zee wrote:
No idea whether this has been discussed before, but I find myself
continuously doing this when sorting arrays with objects:
arr.sort(function(a,b){ if (a.prop b.prop) return-1; if (a.prop
b.prop) return 1; return 0; });
With arrows it is better:
arr.sort((a, b) =
On 01/04/12 18:49, Peter van der Zee wrote:
No idea whether this has been discussed before, but I find myself
continuously doing this when sorting arrays with objects:
arr.sort(function(a,b){ if (a.prop b.prop) return -1; if (a.prop
b.prop) return 1; return 0; });
Couldn't we add an optional
This is all pretty straightforward library work. With Narwhal’s util
module and with my previous work on Chiron, I made some small
composable tools, in much the same spirit as Jeremy Ashkenas’s work on
Underscore. Consider two higher order functions.
by(relation) accepts a relation (a function
On Sun, Apr 1, 2012 at 6:56 PM, Mark S. Miller erig...@google.com wrote:
On Sun, Apr 1, 2012 at 3:53 PM, Brendan Eich bren...@mozilla.org wrote:
arr.sort((a, b) = (a.prop b.prop) ?-1 : (a.prop b.prop) ? 1 : 0);
and if you weed out NaN to avoid the comparison function returning NaN,
Ok, easy goof (I was boarding a plane -- that's my excuse!). But easy to
fix too.
Point is, as Peter posted, this is hard to get right if one has to write
it from scratch. Finding and downloading a standard library? Why not
make that the built-in all implementations provide?
/be
Mark S.
6 matches
Mail list logo