@kingjs/linq.then-by-descending

1.0.7 • Public • Published

@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

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

Analytics

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.then-by-descending

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

4.23 kB

Total Files

4

Last publish

Collaborators

  • kingces95