Created
August 5, 2019 21:20
-
-
Save jerolan/0f2e43fdb099970426162f500f19f9d6 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
/** | |
* 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