deno.land / x / simplestatistic@v7.7.1 / src / numeric_sort.js

numeric_sort.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/** * Sort an array of numbers by their numeric value, ensuring that the * array is not changed in place. * * This is necessary because the default behavior of .sort * in JavaScript is to sort arrays as string values * * [1, 10, 12, 102, 20].sort() * // output * [1, 10, 102, 12, 20] * * @param {Array<number>} x input array * @return {Array<number>} sorted array * @private * @example * numericSort([3, 2, 1]) // => [1, 2, 3] */function numericSort(x) { return ( x // ensure the array is not changed in-place .slice() // comparator function that treats input as numeric .sort(function (a, b) { return a - b; }) );}
export default numericSort;
simplestatistic

Version Info

Tagged at
2 years ago