
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
sort-numbers
Advanced tools
Sort numbers in ascending or descending order
sortNumbers([0.45, Infinity, -2]); //=> [-2, 0.45, Infinity]
sortNumbers.desc([ 0.45, Infinity, -2]); //=> [Infinity, 0.45, -2]
npm install sort-numbers
bower install sort-numbers
var sortNumbers = require('shinnn/sort-numbers.js');
Download the script file directly.
numbers: Array of Number without NaN
Return: Array of Number
It returns the array numerically sorted in ascending order.
Note that Array.prototype.sort works as lexical sort by default.
var arr = [100, -2, -Infinity];
sortNumbers(arr); //=> [ -Infinity, -2, 100 ]
arr.sort(); //=> [ -2, -Infinity, 100 ]
It returns an empty array when the argument is an empty array.
It throws a TypeError when the array contains non-number values or NaN.
sortNumbers(new Array()); //=> []
sortNumbers([1, '2', 3]); // throw a type error
sortNumbers([NaN]); // throw a type error
numbers: Array of Number without NaN
Return: Array of Number
It returns the array numerically sorted in descending order.
var arr = [0, 1, 2 ,3];
sortNumbers.desc(arr) //=> [3, 2, 1, 0]
sortNumbers(arr) //=> [0, 1, 2, 3]
An alias to sortNumbers.
You can use this module as a CLI tool by installing it globally.
npm install -g sort-numbers
Usage: sort-numbers <number0> [<number1> <number2> ...]
Options:
--desc, -d Sort numbers in descending order (ascending order by default)
--help, -h Print usage information
--version, -v Print version
sort-numbers -23 7 -Infinity Infinity
yields:
-Infinity,-23,7,Infinity
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
Licensed under the MIT License.
FAQs
Sort numbers in ascending or descending order
We found that sort-numbers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.