All files / comparator/src numberComparator.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                                    50x 28x    
import { Comparator } from "./_types";
 
/**
 * A {@link Comparator} that orders `number` values by their natural order,
 * i.e. `-1 < 0 < 1`.
 *
 * @example
 * Sort an Array of number values
 * ```ts
 * const array = [3, 1, 2];
 * array.sort(numberComparator);
 * console.log(array); // [1, 2, 3]
 * ```
 *
 * @param numberA - the first number value
 * @param numberB - the second number value
 * @returns a {@link Comparator} for number values
 */
export const numberComparator: Comparator<number> = (numberA, numberB) => {
  return numberA - numberB;
};