Implement a function which will convert the given boolean value into its string representation.
So for the boolean false, return "false"
and for the boolean true, return "true"
Good luck!
This challenge comes from btaitelb on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (12)
shortest version I can think of:
javascript
or a more safe version that wont print
nullorundefined, rather it will convert it to true/false depending on its "truthiness":javascript
Rust
1. return an owned
String:or (on nightly)
or
2. return a reference to a string embedded in the binary:
someone in discord golfed that to
but idk idk :v
Ruby
there already exists a function
to_s.If you want another one, here it is
It will work without the
!!I just wanted to make sure it will work even if anything else is passedMy solution that is submitted to Codewar
My another solution that is accepted
intandchartype.C using _Generic. feel free to contribute
JavaScript
JavaScript
That's pretty heavyweight!
value.toString()works, too.Yes, mine is really really heavy, just tried something no one could think of.
Python:
Some go here
C#
bool.TrueString.ToLower()
bool.FalseString.ToLower()