thenBy(keySelector[, comparer, arg])

Performs a subsequent ordering of the elements in a sequence in ascending order by using a specified comparer.

Syntax

Parameters

keySelector
Type: function(value, key, arg)
A function to extract a key from each element.
comparer
Type: function(value1, value2, arg): number
An comparer to compare keys. Should return 0 if value1 == value2, negative value if value1 < value2, positive value if value1 > value2.
arg
An external argument.
Return Value

An iteratable object whose elements are sorted according to a key.

Examples

var fruits = [ "grape", "passionfruit", "banana", "mango", "orange", "raspberry", "apple", "blueberry" ];

// Sort the strings first by their length and then 
//alphabetically by passing the identity selector function.
var query = $from(fruits).orderBy("$length").thenBy("$");
query.each("document.writeln($)");

/*
 This code produces the following output:

 apple
 grape
 mango
 banana
 orange
 blueberry
 raspberry
 passionfruit
*/

Last edited May 18, 2012 at 10:17 AM by suckgamoni, version 2

Comments

No comments yet.