Skip to content

Instantly share code, notes, and snippets.

@misha-krainik
Created March 5, 2018 16:06
Show Gist options
  • Save misha-krainik/ae10840b1c6862d92e56be29107bf535 to your computer and use it in GitHub Desktop.
Save misha-krainik/ae10840b1c6862d92e56be29107bf535 to your computer and use it in GitHub Desktop.
String reverse.
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