Skip to content

Instantly share code, notes, and snippets.

@a-tarasyuk
Created August 3, 2016 11:17
Show Gist options
  • Save a-tarasyuk/ac262f8d6809b9896f83d707e8396d4f to your computer and use it in GitHub Desktop.
Save a-tarasyuk/ac262f8d6809b9896f83d707e8396d4f to your computer and use it in GitHub Desktop.
function reverse(string) {
var len = string.length,
halfIndex = Math.floor(len / 2),
result = string.split(''),
tmp;
for (var i = 0; i < halfIndex; i++) {
tmp = result[len - i - 1];
result[len - i - 1] = result[i];
result[i] = tmp;
}
return result.join('');
}
console.log(
reverse('test')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment