Get the name of a number, even if it's stupidly big.
Ви не можете вибрати більше 25 тем
Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
Це архівний репозитарій. Ви можете переглядати і клонувати файли, але не можете робити пуш або відкривати питання/запити.
|
- import NAMES from '../names.json'
-
- interface HundredTimes {
- (x100: number): string
- }
-
- /**
- * Get the name of some number in the hundreds place.
- * @param {number} x100 - The number in the hundreds place.
- * @returns {string} The name of the number in the hundreds place.
- */
- const hundredTimes: HundredTimes = (x100) => {
- if (x100 === 0) {
- return NAMES.units[0]
- }
-
- const hundredFactor = NAMES.units[x100]
- let hundredFactorCombining: string
- let infix: string
- let hundredSuffixCombining: string
-
- switch (x100) {
- case 1:
- hundredFactorCombining = hundredFactor.slice(1)
- infix = 'n'
- hundredSuffixCombining = NAMES.hundred
- break
- case 2:
- case 5:
- hundredFactorCombining = hundredFactor
- infix = 'n'
- hundredSuffixCombining = NAMES.hundred
- break
- default:
- case 3:
- case 7:
- case 8:
- hundredFactorCombining = hundredFactor
- infix = 'ng'
- hundredSuffixCombining = NAMES.hundred
- break
- case 4:
- case 6:
- case 9:
- hundredFactorCombining = hundredFactor
- infix = 'na'
- hundredSuffixCombining = 'r' + NAMES.hundred.slice(1)
- break
- }
-
- return [hundredFactorCombining, infix, hundredSuffixCombining].join('')
- }
-
- export default hundredTimes
|