Get the name of a number, even if it's stupidly big.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
Це архівний репозитарій. Ви можете переглядати і клонувати файли, але не можете робити пуш або відкривати питання/запити.

55 рядки
1.2 KiB

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