1.0.7 • Published 6 years ago

@kingjs/linq.then-by-descending v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@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

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago