Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created December 29, 2025 23:55
Show Gist options
  • Select an option

  • Save goofballLogic/4a832d7f65ee063e47ef6660bbb4fa6e to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/4a832d7f65ee063e47ef6660bbb4fa6e to your computer and use it in GitHub Desktop.
const replaceRepeats = (input, number) =>
input.replaceAll(
new RegExp(`${number}+`, "g"),
x => x.length);
// test
[
replaceRepeats('1234500362000440', 0) === "1234523623441",
replaceRepeats('000000000000', 0) == "12",
replaceRepeats('123456789', 1) == "123456789"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment