Skip to content

sortNumberAscFn

Sort numbers in ascending order

Available since v1.9.0

import { sortNumberAscFn } from '@helpers4/array';
// or, from the all-in-one package (same code, one install):
import { sortNumberAscFn } from 'helpers4/array';

Use sortNumberAscFn as a comparator for Array.sort().

[3, 1, 2].sort(sortNumberAscFn)
// => [1, 2, 3]

Use sortStringAscFn for locale-aware string sorting.

['banana', 'apple', 'cherry'].sort(sortStringAscFn)
// => ['apple', 'banana', 'cherry']

View source on GitHub