← Back to challenges

English to Numbers

JavaScriptHardconditionsnumbersstrings

Instructions

This is a companion to yanni's previous challenge.

Given an English description of an integer in the range 0 to 999, devise a function that returns the integer in numeric form.

Examples

engToNums("four") ➞  4

engToNums("forty") ➞ 40

engToNums("six hundred") ➞ 600

engToNums("one hundred fifteen") ➞ 115

engToNums("seven hundred sixty seven") ➞ 767

Notes

  • No hyphens are used in test cases ("twenty three" not "twenty-three").
  • The word "and" is not used: "one hundred three" not "one hundred and three".
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.