Sort array of number
Sun Dec 19 2021 18:25:05 GMT+0000 (UTC)
Saved by
@bapateprachee
#javascript
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;
content_copyCOPY
Comments