function zeros(expression) {
let arr = expression.split('*');
let counter = 0;
let count = 0;
let factorial = arr.filter(item => item.includes("!!") == false);
let fact = factorial.map(function(item) {
let value1 = +item.slice(0, -1);
return value1;
});
let doubleFactorial = arr.filter(item => item.includes("!!") == true);
let doubleFact = doubleFactorial.map(function(item) {
let value1 = +item.slice(0, -2);
return value1;
});
let zeroFactorial = fact.map(function(n) {
if ( n % 2 == 0 && n < 5) {
return 2;
} else if ( n == 1) {
return 1;
} else {
let counter1 = 0;
for (let i = 5; n/i >= 1; i *= 5)
counter1 *= Math.pow(10,Math.floor(n/i));
return counter1*2;
};
});
let zeroDoubleFactorial = doubleFact.map(function(n) {
if ( n % 2 == 0 && n < 10) {
return 2;
} else if ( n % 2 != 0 && n > 3) {
return 5;
} else if ( n <= 3) {
return 1;
} else {
let counter2 = 0;
for (let i = 10; n/i >= 1; i *= 5)
counter2 *= Math.pow(10,Math.floor(n/i));
return counter2*2;
};
});
counter = arrayfunc(zeroFactorial) * arrayfunc(zeroDoubleFactorial);
howMuch(counter);
alert (count);
function arrayfunc(array){
let pr = 1;
for(let j = 0; j < array.length; j++){
pr *= array[j];
};
return pr;
};
function howMuch(num){
for(let x = 10; num % x == 0; x = x*10){
count ++;
};
};
};
zeros('100!!');