How to do it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How to do it

a program that orders numbers and reverses them in an array

9th Aug 2017, 12:35 PM
Tsholofelo Tshenyego
Tsholofelo Tshenyego - avatar
2 Answers
+ 15
[2,6,3,7].sort().reverse() //sorted as characters thus wrong approach
9th Aug 2017, 12:45 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
@VH: this will not work with [42,3,127] ;P Good answer is: alert([42,3,127].sort(function(a,b) {return b-a}));
9th Aug 2017, 1:01 PM
visph
visph - avatar