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.
|
- 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
|