Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Split Reduce solution in Clear category for End Zeros by zoezed
import assert from "assert";
var endZeros = (value: number): number => {
return value.toString().split('').reduce((acc, curr) => {
return curr === '0' ? acc+=1 : acc = 0
},0)
}
console.log('Example:');
console.log(endZeros(0));
//alt var endZeros=(value: number): number =>
// (''+value).match(/0*$/)[0].length;
// 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!");
June 16, 2020
Comments: