Skip to content

Instantly share code, notes, and snippets.

@rd13
Created May 11, 2013 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rd13/5561606 to your computer and use it in GitHub Desktop.
Save rd13/5561606 to your computer and use it in GitHub Desktop.
Javascript - Swap adjacent letters
letterSwap = function(str, swap) {
ot = str.split('');
for( i in str) {
if(i%swap===0) {
ot[i] = str[parseInt(i)+swap-1];
ot[parseInt(i)+swap-1] = str[i];
}
}
return ot.join('');
}
console.log(letterSwap('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment