Created
December 3, 2016 08:05
-
-
Save anonymous/60b9c70e85d0a760509b5de5049de985 to your computer and use it in GitHub Desktop.
Scramble String created by wwebby1 - https://repl.it/E8r2/3
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
// Write a method that takes in a string and an array of indices in the | |
// string. Produce a new string, which contains letters from the input | |
// string in the order specified by the indices of the array of indices. | |
// | |
function scramble(str, indices){ | |
var result = []; | |
for(var i = 0; i < str.length; i++){ | |
result.splice(indices[i], 0, str[i]); | |
} | |
return result.join(""); | |
} | |
scramble("frank", [1, 0, 2, 4, 5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment