Last active
December 29, 2022 11:16
-
-
Save ChrisDobby/885ee7465efd7c08e672687878452766 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 addZerosCount = ({ str, zeroCount }: { str: string; zeroCount: number }) => `${str}${zeroCount || ''}` | |
const replaceZeros = (strIncludingZeros: string) => | |
addZerosCount( | |
strIncludingZeros.split('').reduce((acc, ch) => (ch === '0' ? { ...acc, zeroCount: (acc.zeroCount += 1) } : { str: `${addZerosCount(acc)}${ch}`, zeroCount: 0 }), { | |
str: '', | |
zeroCount: 0, | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment