Get the name of a number, even if it's stupidly big.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Deze repo is gearchiveerd. U kunt bestanden bekijken en het klonen, maar niet pushen of problemen/pull-requests openen.
|
- 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
|