There are so many different ways to express whether something is true or not! The goal of this challenge is to produce a standardized output of truthy
or falsy
for various input truthy and falsy values.
For the purposes of this challenge, the following inputs are considered truthy:
- A string representing a signed integer with a non-zero value (contains only the digits
[0-9]
, with an optional-
at the beginning). Note that the string-0
will never be given as input. A non-zero integer will never be preceded by a0
(i.e.01
will never be given as input, similarly-01
will never be gien as input). - The case-insensitive strings equivalent to one of
defined
,found
,nonnil
,non-nil
,on
,success
,t
,true
,y
, andyes
For the purposes of this challenge, the following inputs are considered falsy:
- The string
0
. Repeated zeros (00
,00...
) will never be given as input. - An empty string
- The case-insensitive strings equivalent to one of
f
,failure
,false
,n
,nan
,nil
,no
,notfound
,not-found
,null
,nullptr
,off
, andundefined
Input
The input is a string representing a truthy/falsy value. The string may come from any source desired (stdio, function parameter, etc.). There is no leading/trailing whitespace.
The input is guaranteed to match one of the allowed truthy/falsy values above (i.e. you do not need to provide any error handling).
Output
Your program/function must output a truthy/falsy value which represents the "truthy-ness" or "falsy-ness" of the input. You are only allowed to specify exactly 1 truthy and 1 falsy value which your output must convert the input to (these are your "standardized" truthy/falsy value). The output may be written to any sink desired (stdio, return value, output parameter, etc.).
Please specify what truthy
and falsy
value you chose in your answer.
Ex.: If you choose the string true
as a truthy value, you cannot also have the integer 1
for truthy.
Test Cases
Test cases are formatted as the first line is the input, and the second line is the output.
-1
true
1
true
1234
true
-4321
true
defined
true
deFined
true
Found
true
nonnil
true
non-nil
true
ON
true
SuCCess
true
T
true
true
true
y
true
YeS
true
0
false
'' (empty string)
false
faLSE
false
f
false
Failure
false
n
false
NaN
false
nil
false
no
false
notfound
false
not-Found
false
NULL
false
nullptr
false
OFF
false
unDefined
false
Scoring
This is code-golf; shortest code in bytes wins. Standard loopholes apply. You may use any built-ins desired.
0
? \$\endgroup\$00
truthy, or are they even valid inputs? (I suppose they are not valid, but just checking) \$\endgroup\$