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 wrote:
> The reason why a custom function is needed is because he wants to sort
> on a key in the javascript object. If it
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;
> 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 exp
In JavaScript the default sort order depends on the data types of the
variables in question. If either is a string, you convert the other
to a string and sort lexicographically, but if both are numbers you
compare numerically. There is a similar inconsistency around what the
"+" operation does.
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.
Chee
> 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:
>
> va
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 = func