linq.OrderByDescending

Orders elements in an array, highest value to lowest

Overloads

  • Array OrderByDescending ()
  • Array OrderByDescending (selector)
  • Array OrderByDescending (selector, comparator)

Array OrderByDescending ()

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

Example

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

Array OrderByDescending (selector)

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

Example

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

Array OrderByDescending (selector, comparator)

Orders elements in an array based on the selected property, highest value to lowest, 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: "Why Hello!"}, {x: "Chickens"}, {x: "Hi"}, {x: "a"}]
myArray.OrderByDescending("o=>o.x", "(a, b) => a.length > b.length ? 1 : a.length < b.length ? -1 : 0");

Last edited Sep 24, 2011 at 5:40 AM by mlorbetske, version 2

Comments

No comments yet.