Last active
February 12, 2018 13:00
-
-
Save dagolinuxoid/d10ad12873e09e318509b2b163474250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PS. twenty-five is more common then twenty five I belive, so I used dash. | |
const apm=(num)=>num<12?'AM':'PM'; | |
const hh=(num)=>{ | |
const ones=['twelve','one','two','three','four','five','six','seven','eight','nine','ten','eleven']; | |
return ones[num%12]; | |
}; | |
const mm=(num)=>{ | |
if(num==='00') return ''; | |
if(num<10) return `oh ${hh(num[1])}`; | |
const teens=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']; | |
if(num<20) return teens[num-10]; | |
const bigs={2:'twenty',3:'thirty',4:'fourty',5:'fifty'}; | |
return num[1]==='0' ? bigs[num[0]] : bigs[num[0]]+'-'+hh(num[1]); | |
}; | |
const res=(str)=>{ | |
const s=str.split(':'); | |
if (mm(s[1])==='') return "It's "+hh(s[0])+" "+apm(s[0]); // gotcha did you get it? | |
return `It's ${hh(s[0])} ${mm(s[1])} ${apm(s[0])}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment