alphanumeric sort

Eric Moritz eric at themoritzfamily.com
Thu May 12 11:40:40 EDT 2011


That's what I get for coding in gmail, that function signature
obviously should be:

Riak.reduceSortByField(values, key) { ... }

On Thu, May 12, 2011 at 2:46 AM, Eric Moritz <eric at themoritzfamily.com> wrote:
> The reason why a custom function is needed is because he wants to sort
> on a key in the javascript object.  If it was a list of strings,
> calling .sort() would be fine.  We need a
>
> Riak.reduceSortByField(values, name) {
>    return values.sort(function(x,y) {
>      if(a[key] == b[key]) return 0;
>      return a[key] > b[key] ? 1 : -1;
>     });
> }
>
> On Thu, May 12, 2011 at 2:21 AM, Claus Guttesen <kometen at gmail.com> wrote:
>>> Iirc, "sort()" is by default lexographic in JavaScript so an added function
>>> is not necessary. The added function is specifically intended for a custom
>>> sort, ie. numerical.
>>>
>>> You could simply do something like:
>>>
>>> return v['key'].sort()
>>>
>>> Try that out and lemme know if it works as you expect.
>>
>> I tried it but it didn't work. And I believe sort expects a list like
>> [3, 5, 8, 1] but I have an array with json-formatted objects and have
>> to inspect each element as described in the link I referred to in my
>> OP.
>>
>> --
>> 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