Skip to content

Instantly share code, notes, and snippets.

@jerolan
Created August 5, 2019 21:20
Show Gist options
  • Save jerolan/0f2e43fdb099970426162f500f19f9d6 to your computer and use it in GitHub Desktop.
Save jerolan/0f2e43fdb099970426162f500f19f9d6 to your computer and use it in GitHub Desktop.
/**
* Blowup
* Write a function which takes a string and returns the blowup of said string.
*
* Definition. Blowup of a string.
* The blowup of a string
* s = "a1a2a3..."
* is defined by
* blowup = "a1a2a2a3a3a3..."
* Flor example, the blowup of "bang!" is "baannngggg!!!!!"
*
* Test Cases
*
* > blowup "bang!"
* "baannngggg!!!!!"
*
* > blowup "hi!"
* "hii!!!"
*
* > blowup ""
* ""
*/
function blowup(string) {
return string.split("").reduce((blow, char, times) => {
return blow + char.repeat(times + 1);
}, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment