linq.OrderBy

Orders elements in an array, lowest value to highest

Overloads

  • Array OrderBy ()
  • Array OrderBy (selector)
  • Array OrderBy (selector, comparator)

Array OrderBy ()

Orders elements in an array, lowest value to highest, using the default comparator

Example

var myArray = [5,3,2,1,7,23];
//Returns [1, 2, 3, 5, 7, 23]
myArray.OrderBy();

Array OrderBy (selector)

Orders elements in an array based on the selected property, lowest value to highest, using the default comparator

Example

var myArray = [{x: 5}, {x: 3}, {x: 2}, {x: 1}, {x: 7}, {x: 23}];
//Returns [{x: 1}, {x: 2}, {x: 3}, {x: 5}, {x: 7}, {x: 23}]
myArray.OrderBy("o=>o.x");

Array OrderBy (selector, comparator)

Orders elements in an array based on the selected property, lowest value to highest, using the specified comparator
Note: If null is passed for the selector, the default selector "x=>x" is used

Example

var myArray = [{x: "Hi"}, {x: "Why Hello!"}, {x: "a"}, {x: "Chickens"}];
//Returns [{x: "a"}, {x: "Hi"}, {x: "Chickens"}, {x: "Why Hello!"}]
myArray.OrderBy("o=>o.x", "(a, b) => a.length > b.length ? 1 : a.length < b.length ? -1 : 0");

Last edited Sep 24, 2011 at 5:25 AM by mlorbetske, version 1

Comments

No comments yet.