@kingjs/linq.then-by-descending
v1.0.7
Published
Generates a sequence of elements from a sorted sequence where elements previously considered equal are put in descending order according to a key.
Downloads
5
Readme
@kingjs/linq.then-by-descending
Generates a sequence of elements from a sorted sequence where elements previously considered equal are put in descending order according to a key.
Usage
Sort Bob Smith
, Alice Smith
, and Chris King
in descending order by last name then first name like this:
var orderByDescending = require('@kingjs/linq.order-by-descending');
var thenByDescending = require('@kingjs/linq.then-by-descending');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');
var people = sequence(
{ first: 'Bob', last: 'Smith' },
{ first: 'Alice', last: 'Smith' },
{ first: 'Chris', last: 'King' },
);
var lastSelector = function(x) { return x.last; }
var firstSelector = function(x) { return x.first; }
var sortedSequence = orderByDescending.call(people, lastSelector);
sortedSequence = thenByDescending.call(sortedSequence, firstSelector);
toArray.call(sortedSequence);
result:
[
{ first: 'Bob', last: 'Smith' },
{ first: 'Alice', last: 'Smith' },
{ first: 'Chris', last: 'King' },
]
API
declare function thenByDescending(
this: SortedEnumerable,
keySelector?: (x) => any,
lessThan?: (l, r) => boolean,
): SortedEnumerable
Interfaces
SortedEnumerable
: See @kingjs/linq.order-by.
Parameters
this
: A sorted sequence of element to subsequently sort.keySelector
: Select a value by which to sort. By default, returns the element.lessThan
: Compare if one key is less than another. By default, uses the<
operator.
Return Value
A refined sorted sequence in descending order.
See Also
Install
With npm installed, run
$ npm install @kingjs/link.then-by-descending
Acknowledgments
Like Enumerable.ThenByDescending
License
MIT