Get the name of a number, even if it's stupidly big.
Du kan inte välja fler än 25 ämnen
Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
Den här utvecklingskatalogen är arkiverad. Du kan se filer och klona katalogen, men inte öppna ärenden eller genomföra push- eller pull-förfrågningar.
|
- import { Digit } from '../../../common'
- import NAMES from '../names'
-
- interface HundredTimes {
- (x100: Digit): 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 (Number(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
|