const numbers = [45, 5, 1, 0, 22, 60, 90, 78]; //normal sort method does not work numbers.sort( (a, b) { return b - a; } ); numbers.sort( (a,b ) => b - a ); // if a is greater then we should return -1 // if b is greater then we should return 1 // if a equals b then we should return 0;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter