Advertisement
xerocool-101

008 sort

Apr 20th, 2025 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.20 KB | Software | 0 0
  1. // Sort Array
  2. // Asc
  3. const nums = [3, 1, 5];
  4. nums.sort((a, b) => a - b);
  5. console.log(nums); // [1, 3, 5]
  6.  
  7. // Desc
  8. const nums = [3, 1, 5];
  9. nums.sort((a, b) => b - a);
  10. console.log(nums); // [5, 3, 1]
Tags: JavaScript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement