Last active
February 22, 2023 19:35
-
-
Save KEIII/6e6d3e0eac190d362af101e91fa4d5c5 to your computer and use it in GitHub Desktop.
This file contains 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
// hack | |
const f1 = (n) => String(n).length; | |
// log10 | |
const f2 = (n) => Math.floor(Math.log10(n) + 1); | |
// recursive | |
const f3 = (n) => { | |
if (n < 10) return 1; | |
return 1 + fc(n / 10); | |
}; | |
// while | |
const f4 = (n) => { | |
if (n === 0) { | |
return 1; | |
} | |
let result = 0; | |
while (n > 0) { | |
n = Math.trunc(n / 10); | |
result++; | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment