Created
May 11, 2013 22:11
-
-
Save rd13/5561606 to your computer and use it in GitHub Desktop.
Javascript - Swap adjacent letters
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
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