How to sort an array in reverse order with TypeScript

1 Answer

0 votes
let arr = [3, 6, 7, 5, 9, 1, 2];

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

console.log(arr);
 
   
   
   
   
/*
run:
   
[9, 7, 6, 5, 3, 2, 1] 
   
*/

 



answered Apr 24, 2022 by avibootz
...