Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/statistics/src/utils/numeric_sort.ts>numericSort

Deno basic statistics module.
Latest
function numericSort
import { numericSort } from "https://deno.land/x/statistics@v0.1.1/src/utils/numeric_sort.ts";

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]

Examples

numericSort([3, 2, 1]) // => [1, 2, 3]

Parameters

x: number[]

input array

Returns

number[]

sorted array