Text Cleanup

Sort Numerically

Sort a list of numbers in the correct mathematical order.

Explanation

Standard alphabetical sorting puts "10" before "2". Numeric sorting treats strings as values.

Examples

Number List
Input
10
2
1
20
Output
1
2
10
20

Code Examples

JavaScript
const sorted = input.split('\n')
  .sort((a, b) => Number(a) - Number(b))
  .join('\n');

Try it Now

💡 Tips

  • Works for both integers and decimals
  • Remove non-numeric characters before sorting if necessary
  • Useful for IDs, prices, and timestamps

⚠️ Common Pitfalls

  • Fails if lines contain currency symbols or units without cleaning