@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.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
04Jun 21, 2021Jul 20, 2018Minified + gzip package size for @kingjs/linq.then-by-descending in KB

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

Parameters

Analytics

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.