-
-
Save lwebber/8384f23490d028a1e4e9300161b8d8d8 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