Advertisement
Spocoman

05. Sort an Array by 2 Criteria

Feb 7th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sortingBy2Criteria(arr) {
  2.  
  3.     arr.sort((a, b) => {
  4.         if (a.length === b.length) {
  5.             return a.localeCompare(b)
  6.         }
  7.         return a.length > b.length ? 1 : -1;
  8.     });
  9.     console.log(arr.join('\n'));
  10. }
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement