alphanumeric sort

Claus Guttesen kometen at gmail.com
Wed May 11 16:10:43 EDT 2011


> Your compare function will need to return a -1, 0 or 1 for less than,
> the same or greater than.  Luckily javascript allows you
> to strings lexicographically so the function is a nice two liner:
>
> function(a, b) {
>   if(a == b) return 0;
>   return a > b ? 1 : -1;
> }
>
> Application:
>
> var reduceSort = function (v, args) {
>  return v.sort (function(a, b) {
>   if(a['key'] == b['key']) return 0;
>   return a['key'] > b['key'] ? 1 : -1;
>  });
> };
>
> Eric.

Thank you so much! :-) Worked like a charm.

-- 
regards
Claus

When lenity and cruelty play for a kingdom,
the gentler gamester is the soonest winner.

Shakespeare

twitter.com/kometen




More information about the riak-users mailing list