Skip to content

Instantly share code, notes, and snippets.

@nkitku
Last active March 24, 2020 08:08
Show Gist options
  • Save nkitku/53d4f1352f7d4e4b021f54f5dc768cfe to your computer and use it in GitHub Desktop.
Save nkitku/53d4f1352f7d4e4b021f54f5dc768cfe to your computer and use it in GitHub Desktop.
Up To 102 digit Number to Word Smallest Code in Javascript ES6
nw=((e,n="Eigh",t=e=>e.split(/(?=[A-Z])|,/),i=(e,n)=>e.map(e=>e+n),r=t(`,OneTwoThreeFourFiveSixSevenEightNine`),o=["",,...i(["Twen",e="Thir","For",...n=["Fif",r[6],r[7],n,r[9]]],"ty")],u=["Ten","Eleven","Tweleve",...i([e,r[4],...n],"teen")],T=[n="","Thousand ",...i([...t("MBTrQuadrQuintSextSeptOctNonDec"),...i(e=t("UnDuoTreQuattuorQuinSexSeptenOctoNovem"),"dec"),...i(["V",...i(e,"v"),"Tr","Untr","Duotr"],"igint")],"illion ")])=>(i,l=(i+=n).length,d=0)=>[...i].reduce((v,S,c)=>(e=l-c,v+=(e+1)%3?(t=d?(d=0,u[S]):r[S],t&&t+" ")+((e+2)%3&&+S?"Hundred ":n):1==S?(d=1,n):o[S]&&o[S]+" ",v+=T[(t=e-1)%3==0?(+i[c-2]||+i[c-1]||+S)&&t/3:0]),n).trim()||"Zero")();
@nkitku
Copy link
Author

nkitku commented Mar 24, 2020

	 nw('9'.repeat(102))
Nine Hundred Ninety Nine Duotrigintillion Nine Hundred Ninety Nine Untrigintillion Nine Hundred Ninety Nine Trigintillion
Nine Hundred Ninety Nine Novemvigintillion Nine Hundred Ninety Nine Octovigintillion Nine Hundred Ninety Nine Septenvigintillion
Nine Hundred Ninety Nine Sexvigintillion Nine Hundred Ninety Nine Quinvigintillion Nine Hundred Ninety Nine Quattuorvigintillion
Nine Hundred Ninety Nine Trevigintillion Nine Hundred Ninety Nine Duovigintillion Nine Hundred Ninety Nine Unvigintillion
Nine Hundred Ninety Nine Vigintillion Nine Hundred Ninety Nine Novemdecillion Nine Hundred Ninety Nine Octodecillion
Nine Hundred Ninety Nine Septendecillion Nine Hundred Ninety Nine Sexdecillion Nine Hundred Ninety Nine Quindecillion
Nine Hundred Ninety Nine Quattuordecillion Nine Hundred Ninety Nine Tredecillion Nine Hundred Ninety Nine Duodecillion
Nine Hundred Ninety Nine Undecillion Nine Hundred Ninety Nine Decillion Nine Hundred Ninety Nine Nonillion
Nine Hundred Ninety Nine Octillion Nine Hundred Ninety Nine Septillion Nine Hundred Ninety Nine Sextillion
Nine Hundred Ninety Nine Quintillion Nine Hundred Ninety Nine Quadrillion Nine Hundred Ninety Nine Trillion
Nine Hundred Ninety Nine Billion Nine Hundred Ninety Nine Million Nine Hundred Ninety Nine Thousand 
Nine Hundred Ninety Nine```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment