Im trying return an int that count the last Zeros of an int, but I can´t to stop the flow of the loop when it finds something that is not zero. whats wrong?
const endZeros = (value) => {
const stringValue = `${value}`
const arrValue = stringValue.split("").reverse()
let total = 0;
arrValue.map(el => {
if (el === "0") {
total = total + 1
} else {
return // I check return false too (and true, and all! --> desesperation)
}
})
return total;
}
endZeros(100100)
Thank You, everyone ❤️
How about a simple regexp?
const lastZeros = num => { const zeros = String(num).match(/0+$/); return zeros ? zeros[0].length : 0 };
console.log(lastZeros(100100))
console.log(lastZeros(111111))
console.log(lastZeros(101000))