Created
August 3, 2016 11:17
-
-
Save a-tarasyuk/ac262f8d6809b9896f83d707e8396d4f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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