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

Which fix removes the bug?

function parseFlag(v?: string): boolean {
  return v.toLowerCase() === "true";
}
  1. Guard: return v?.toLowerCase() === "true"
  2. Change the return type to string
  3. Remove the ? from v? in the body
  4. Change === to == in the comparison
v may be undefined; use optional chaining before calling.
Play Problem Solving ▸