DEV Community

Discussion on: JavaScript code puzzle: convert a Boolean to Number

Collapse
 
snigo profile image
Igor Snitkin

Up to 3 characters:

const fn_not = b => ~~b;
const fn_inc = b => b++;
const fn_nry = b => +b; // might fall under `toNumber` implementation
Enter fullscreen mode Exit fullscreen mode

Cool stuff, keep it up!

Collapse
 
jankapunkt profile image
Jan Küster

Another solution with same length would be

Spoiler
fn=b=>b/1
Enter fullscreen mode Exit fullscreen mode

I counted the function too, which I came up to 9 characters