Get the name of a number, even if it's stupidly big.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
To repozytorium jest zarchiwizowane. Możesz wyświetlać pliki i je sklonować, ale nie możesz do niego przepychać zmian lub otwierać zgłoszeń/Pull Requestów.

56 wiersze
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