Skip to main content

Sort an array of numbers

JavaScript version

const sort = (arr) => arr.sort((a, b) => a - b);

TypeScript version

const sort = (arr: number[]): number[] => arr.sort((a, b) => a - b);

Example

sort([1, 5, 2, 4, 3]); // [1, 2, 3, 4, 5]

Comments