Hekell

Sort n uSort [ES]

Oct 23rd, 2020
857
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let arrays = [2, 1, 6, 2, 5, 1, 9]
  2.  
  3. function realSort(arrays) {
  4.   let emptyArray = []
  5.  
  6.   for (let arr of arrays) {
  7.     let arrayNo = arrays.length - 1
  8.     for (let arr2 of arrays) {
  9.  
  10.       if (arr > arr2) {
  11.         arrayNo--
  12.       }
  13.  
  14.     }
  15.  
  16.     let no = emptyArray[arrayNo] ? arrayNo - 1 : arrayNo
  17.     emptyArray[no] = arr
  18.   }
  19.   return emptyArray
  20. }
  21.  
  22. function realUsort(arrays) {
  23.   let emptyArray = []
  24.  
  25.   for (let arr of arrays) {
  26.     let arrayNo = arrays.length - 1
  27.     for (let arr2 of arrays) {
  28.  
  29.       if (arr < arr2) {
  30.         arrayNo--
  31.       }
  32.  
  33.     }
  34.  
  35.     let no = emptyArray[arrayNo] ? arrayNo - 1 : arrayNo
  36.     emptyArray[no] = arr
  37.   }
  38.   return emptyArray
  39. }
  40.  
  41. console.log(realSort(arrays))
  42. console.log(realUsort(arrays))
RAW Paste Data