Write a function fn that receives a Boolean and returns it's representation as a Number. So true becomes 1 and false becomes 0.
Contstraints:
- no
Numberconstructor or any of it's prototype allowed - no
Mathfunctions allowed - no
toNumberimplementations allowed either - Strings of numbers, such as
'1'and'0'do not count - Assume the function always receives a valid boolean (so no
nullorundefinedor other types need to be considered).
Tests:
console.assert(fn(true) === 1)
console.assert(fn(false) === 0)
Note:
It's marked as #beginners, because it's solution easier than you might think.
Bonus:
It's possible to solve it with 9 characters overall.
117

被折叠的 条评论
为什么被折叠?



