Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Beginning Zeros by ibonyun
import assert from "assert";
function beginningZeros(text: string): number {
for (var i = 0; text[i] === '0'; i++);
return i;
}
console.log('Example:');
console.log(beginningZeros('100'));
// These "asserts" are used for self-checking
assert.equal(beginningZeros('100'), 0);
assert.equal(beginningZeros('001'), 2);
assert.equal(beginningZeros('100100'), 0);
assert.equal(beginningZeros('001001'), 2);
assert.equal(beginningZeros('012345679'), 1);
assert.equal(beginningZeros('0000'), 4);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
July 2, 2021
Comments: