Parse Boolean

Easy~10 min

Given a string, parse it as a boolean value using the following rules:

Truthy strings: "true", "True", "TRUE", "1", "yes", "Yes", "YES"

Falsy strings: "false", "False", "FALSE", "0", "no", "No", "NO"

Anything else (including empty string): return false.

The matching should be exact — no trimming of whitespace, no partial matches.

Examples

Example 1
Input: s = "true"
Output: true
Explanation: "true" is in the truthy list.
Example 2
Input: s = "YES"
Output: true
Explanation: "YES" is in the truthy list.
Example 3
Input: s = "maybe"
Output: false
Explanation: "maybe" is not in either list, so it defaults to false.

Constraints

  • 0 <= s.length <= 50
  • s consists of printable ASCII characters.
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run