Get the name of a number, even if it's stupidly big.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

56 rindas
1.3 KiB

  1. import { Digit } from '../../../common'
  2. import NAMES from '../names'
  3. interface HundredTimes {
  4. (x100: Digit): string
  5. }
  6. /**
  7. * Get the name of some number in the hundreds place.
  8. * @param {number} x100 - The number in the hundreds place.
  9. * @returns {string} The name of the number in the hundreds place.
  10. */
  11. const hundredTimes: HundredTimes = (x100) => {
  12. if (x100 === 0) {
  13. return NAMES.units[0]
  14. }
  15. const hundredFactor = NAMES.units[x100]
  16. let hundredFactorCombining: string
  17. let infix: string
  18. let hundredSuffixCombining: string
  19. switch (Number(x100)) {
  20. case 1:
  21. hundredFactorCombining = hundredFactor.slice(1)
  22. infix = 'n'
  23. hundredSuffixCombining = NAMES.hundred
  24. break
  25. case 2:
  26. case 5:
  27. hundredFactorCombining = hundredFactor
  28. infix = 'n'
  29. hundredSuffixCombining = NAMES.hundred
  30. break
  31. default:
  32. case 3:
  33. case 7:
  34. case 8:
  35. hundredFactorCombining = hundredFactor
  36. infix = 'ng'
  37. hundredSuffixCombining = NAMES.hundred
  38. break
  39. case 4:
  40. case 6:
  41. case 9:
  42. hundredFactorCombining = hundredFactor
  43. infix = 'na'
  44. hundredSuffixCombining = 'r' + NAMES.hundred.slice(1)
  45. break
  46. }
  47. return [hundredFactorCombining, infix, hundredSuffixCombining].join('')
  48. }
  49. export default hundredTimes