Created
December 20, 2017 08:09
-
-
Save pietrom/4a6665a083ba84ae5f054ff3a0854db9 to your computer and use it in GitHub Desktop.
Calculate the number of leading zeroes in n!
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
function range(first, last) { | |
const length = last - first + 1 | |
return new Array(length).fill(-1, 0, length).map(function(v, i) { return i + first; }) | |
} | |
function factZeros(n) { | |
return range(1, Math.floor(Math.log(n) / Math.log(5))).map(x => Math.pow(5, x)).map(x => Math.floor(n / x)).reduce((acc, curr) => acc + curr, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment