Created
March 5, 2018 16:06
-
-
Save mykhailokrainik/ae10840b1c6862d92e56be29107bf535 to your computer and use it in GitHub Desktop.
String reverse.
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
arr = Array.from("Hello world!"); | |
arrLen = arr.length; | |
arrMidLen = Math.floor(arrLen / 2); | |
arr.forEach(function(v, i) { | |
if (arrMidLen > i) { return } | |
var f = arr[i]; | |
var e = arr[arrLen - i - 1]; | |
arr[i] = e; | |
arr[arrLen - i - 1] = f; | |
}); | |
console.log(arr.join('')); // !dlrow olleH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment