$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #169

Which fix removes the bug?

function parse(input: string): number {
  return JSON.parse(input);
}
  1. Validate the parsed value
  2. Change the return to any
  3. Cast the result as number
  4. Add a try/catch block
JSON.parse returns any, so the annotation is a promise the code never checks.
Play Problem Solving ▸