Created
July 30, 2011 13:05
-
-
Save mstepniowski/1115506 to your computer and use it in GitHub Desktop.
getReversed - A solution to one of the problems on meet.js Warsaw
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
function getReversed (str) { | |
var i, idx, result = []; | |
for (i = 0; i < str.length; ++i) { | |
idx = (i % 2) ? (str.length - Math.ceil((i + 1) / 2)) : Math.ceil(i / 2); | |
result.push(str[idx]); | |
} | |
return result.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment