daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest May 16th, 2018 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta charset="utf-8">
  5.   <meta name="viewport" content="width=device-width">
  6.   <title>Sort - one, three, two</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. var num = "zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split(" ");
  12. var tens = "twenty thirty forty fifty sixty seventy eighty ninety".split(" ");
  13. function number2words(n){
  14.   // works for numbers between 0 and 999999  
  15.   if(n<20){
  16.   //console.log(num[n]);
  17.     return num[n];
  18.   }
  19.   var digit = n%10;
  20.   if (n < 100){
  21.  // console.log(tens[~~(n/10)-2] + (digit? "-" + num[digit]: ""));
  22.     return tens[~~(n/10)-2] + (digit? "-" + num[digit]: "");
  23.   }
  24.   if (n < 1000) {
  25.   //console.log( num[~~(n/100)] +" hundred" + (n%100 == 0? "": " " + number2words(n%100)));
  26.   return num[~~(n/100)] +" hundred" + (n%100 == 0? "": " " + number2words(n%100));
  27.   }
  28. }
  29. const sortByName = arr => {
  30.     const words = {};
  31.     arr.forEach(n => words[n] = num2word(n));
  32.     return arr.sort((a, b) => words[a].localeCompare(words[b]));
  33.   };
  34. </script>
  35.  
  36.  
  37.  
  38. <script id="jsbin-source-javascript" type="text/javascript">var num = "zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split(" ");
  39. var tens = "twenty thirty forty fifty sixty seventy eighty ninety".split(" ");
  40. function number2words(n){
  41.   // works for numbers between 0 and 999999  
  42.   if(n<20){
  43.   //console.log(num[n]);
  44.     return num[n];
  45.   }
  46.   var digit = n%10;
  47.   if (n < 100){
  48.  // console.log(tens[~~(n/10)-2] + (digit? "-" + num[digit]: ""));
  49.     return tens[~~(n/10)-2] + (digit? "-" + num[digit]: "");
  50.   }
  51.   if (n < 1000) {
  52.   //console.log( num[~~(n/100)] +" hundred" + (n%100 == 0? "": " " + number2words(n%100)));
  53.   return num[~~(n/100)] +" hundred" + (n%100 == 0? "": " " + number2words(n%100));
  54.   }
  55. }
  56. const sortByName = arr => {
  57.     const words = {};
  58.     arr.forEach(n => words[n] = num2word(n));
  59.     return arr.sort((a, b) => words[a].localeCompare(words[b]));
  60.   };</script></body>
  61. </html>
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