Skip to content

Instantly share code, notes, and snippets.

@dbalatero
Created December 26, 2022 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbalatero/55c927331d08d893663dd5189b48dd48 to your computer and use it in GitHub Desktop.
Save dbalatero/55c927331d08d893663dd5189b48dd48 to your computer and use it in GitHub Desktop.
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