Created
March 17, 2016 00:12
-
-
Save aleclarson/63b616a73b0ecd4e133d to your computer and use it in GitHub Desktop.
Count the number of digits (before the decimal) in a number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (n) -> | |
n = Math.abs n | |
return 1 if n < 1 | |
count = 0 | |
while n >= 1 | |
count += 1 | |
n /= 10 | |
count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment