Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
chain-able-deps / src / loop / sort / _ascending.ts
Size: Mime:
import curry from '../../fp/curry'

type ToLeft<Left> = Left extends [] ? ArrayToValues<Left> : Left
type ToRight<Right> = Right extends [] ? ArrayToValues<Right> : Right

/**
 * Makes an ascending comparator function out of a function that returns a value
 * that can be compared with `<` and `>`.
 * @since 5.0.0-beta.7
 * @memberOf loop
 *
 * @param {Function} fn A function of arity one that returns a value that can be compared
 * @param {*} a The first item to be compared.
 * @param {*} b The second item to be compared.
 * @return {Number} `-1` if fn(a) < fn(b), `1` if fn(b) < fn(a), otherwise `0`
 *
 * @fork v0.23.0
 * @category Function
 * @sig Ord b => (a -> b) -> a -> a -> Number
 * @func
 *
 * @see R.descend
 *
 * @example
 *
 *      var byAge = R.ascend(R.prop('age'));
 *      var people = [
 *        // ...
 *      ];
 *      var peopleByYoungestFirst = R.sort(byAge, people);
 */
export default curry(2, function compareAscending<Left, Right>(
  fn: (ab: any) => number,
  a: ToLeft<Left>,
  b: ToRight<Right>
) {
  const aa = fn(a)
  const bb = fn(b)
  return aa < bb ? -1 : aa > bb ? 1 : 0
})