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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

30 line
582 B

  1. import getHundredName from './getHundredName'
  2. import NAMES from './names.json'
  3. interface GetThousandName {
  4. (hundreds: number, tens: number, ones: number): string,
  5. }
  6. const getThousandName: GetThousandName = (hundreds, tens, ones) => {
  7. if (hundreds === 0) {
  8. return getHundredName(tens, ones)
  9. }
  10. if (tens === 0 && ones === 0) {
  11. return [
  12. NAMES.base.units[hundreds],
  13. NAMES.hundred,
  14. ]
  15. .join(' ')
  16. }
  17. return [
  18. NAMES.base.units[hundreds],
  19. NAMES.hundred,
  20. getHundredName(tens, ones),
  21. ]
  22. .join(' ')
  23. }
  24. export default getThousandName