API Reference

Returns an array of numbers (or strings of numbers) sorted. This is safer than the default sort() method because it converts strings of numbers to actual numbers and it compares each value for greater than less than, which helps when sorting negative numbers.

type StringOrNumberArray = (string | number)[]

function safeSort(arr: StringOrNumberArray): StringOrNumberArray

// Example:

// Standard JS sort
[-1, -2, -3, -4].sort() //=> [-1, -2, -3, -4]

safeSort([-1, -2, -3, -4]) //=> [-4, -3, -2, -1]

// Standard JS sort
["45", "167", "23", "1000"].sort() //=> ["1000", "167", "23", "45"]

safeSort(["45", "167", "23", "1000"]) //=> ["23", "45", "167", "1000"]