Skip to content

Instantly share code, notes, and snippets.

@lwebber
Forked from anonymous/Scramble String.js
Created December 3, 2016 08:05
Show Gist options
  • Save lwebber/8384f23490d028a1e4e9300161b8d8d8 to your computer and use it in GitHub Desktop.
Save lwebber/8384f23490d028a1e4e9300161b8d8d8 to your computer and use it in GitHub Desktop.
Scramble String created by wwebby1 - https://repl.it/E8r2/3
// 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