That was my original version, then I thought writing two functions might confuse people so I changed it into this. It's just for the sake of demonstration and better readability.π€But you were right, it is a bad habit to extend a native prototype.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you convert the number to binary, the steps are exactly
(
number of 1s
- 1) * 2 +number of 0s
This way we donβt need loops or recursion.
Wow this is brilliant! Nice job!
I was about to submit something like that, so have my applause instead ππ
A little more thinking on the problem can really simplify the solution!
(On a side note, I wouldn't extend a native prototype, but that's out of context now π )
That was my original version, then I thought writing two functions might confuse people so I changed it into this. It's just for the sake of demonstration and better readability.π€But you were right, it is a bad habit to extend a native prototype.