SHARE
TWEET

Untitled

a guest Sep 16th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sortOnReverseArray(arr) {
  2.  
  3.   return arr.sort((item, item2) => {
  4.     item = item.split("").reverse().join("").toLowerCase();
  5.     item2 = item2.split("").reverse().join("").toLowerCase();
  6.      if (item < item2) {
  7.        return -1;
  8.      } else if (item > item2) {
  9.        return 1;
  10.      } else {
  11.        return 0;
  12.      }
  13.   })
  14.  
  15. }
  16.  
  17. console.log(sortOnReverseArray(["cat", "dog", "bOG", "elephant", "crocodile"]));
  18. //["crocodile", "bOG", "dog", "cat", "elephant"]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top