Last active
March 25, 2019 02:17
-
-
Save circa10a/3d6ef8f7cdc65c9349ebabdb428da18c to your computer and use it in GitHub Desktop.
javascript reverse array (no helper methods)
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
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