Created
December 26, 2022 16:01
-
-
Save dbalatero/55c927331d08d893663dd5189b48dd48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const replaceZeros = (str) => { | |
return str.replaceAll(/0+/g, (match) => { | |
return match.length.toString(); | |
}); | |
}; | |
console.log(replaceZeros('1234500362000440') === '1234523623441'); | |
console.log(replaceZeros('123450036200044') === '123452362344'); | |
console.log(replaceZeros('000000000000') === '12'); | |
console.log(replaceZeros('123456789') === '123456789'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment