Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
while loop solution in Clear category for End Zeros by dbirmajer
import assert from "assert";
function endZeros(value: number): number {
let count = 0;
if (value === 0) return 1
while (value % 10 === 0){
count++;
value = value / 10;
}
return count;
}
console.log('Example:');
console.log(endZeros(0));
// These "asserts" are used for self-checking
assert.equal(endZeros(0), 1);
assert.equal(endZeros(1), 0);
assert.equal(endZeros(10), 1);
assert.equal(endZeros(101), 0);
assert.equal(endZeros(245), 0);
assert.equal(endZeros(100100), 2);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
Jan. 15, 2021
Comments: