Trailing Zeros

Published by Mubashir Hassan in

Mubashir needs your help to find out trailing zeros after calculating factorial of a given number.

Create a function which takes a number n and calculates the number of trailing zeros in factorial of the given number.

n! = 1 * 2 * 3 * ... * n

Examples

trailingZeros(0) ➞ 0
// 0! = 1
// No trailing zero.

trailingZeros(6) ➞ 1
// 6! = 720
// 1 trailing zero.

trailingZeros(1000) ➞ 249
// 1000! has 249 trailing zeros.

Notes

Hint: No need to calculate the factorial (because it won't help). Find another way to find the number of zeros.

Watch a quick demo on how Edabit works.