Created
December 19, 2018 11:48
-
-
Save malisetti/fe2d6c7747eab6d5f631aa7c642d5619 to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
const assert = require("assert"); | |
(() => { | |
const inouts = { | |
Code: "CCoCodCode", | |
abc: "aababc", | |
ab: "aab" | |
}; | |
for (const input in inouts) { | |
if (inouts.hasOwnProperty(input)) { | |
const output = inouts[input]; | |
assert.equal(output, stringSplosion(input), "fail"); | |
} | |
} | |
})(); | |
/** | |
* Given a non-empty string like "Code" return a string like "CCoCodCode". | |
stringSplosion("Code") → "CCoCodCode" | |
stringSplosion("abc") → "aababc" | |
stringSplosion("ab") → "aab" | |
*/ | |
function stringSplosion(str) { | |
let strx = ""; | |
const l = str.length; | |
for (let i = 1; i <= l; i++) { | |
strx += str.substr(0, i); | |
} | |
return strx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment