Skip to content

Instantly share code, notes, and snippets.

@circa10a
Last active March 25, 2019 02:17
Show Gist options
  • Save circa10a/3d6ef8f7cdc65c9349ebabdb428da18c to your computer and use it in GitHub Desktop.
Save circa10a/3d6ef8f7cdc65c9349ebabdb428da18c to your computer and use it in GitHub Desktop.
javascript reverse array (no helper methods)
const arr = [1, 2, 3, 4, 5];
const newArr = [];
for(i = arr.length; i >=arr[0]; i--) {
newArr.push(i);
}
console.log(newArr); // [ 5, 4, 3, 2, 1 ]
/* with helper method (recommended)
newArr = arr.reverse();
console.log(newArr);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment