Created
August 22, 2019 19:37
-
-
Save DanielHemmati/3aaa48e36c6775a43df4ca65f6ed7af0 to your computer and use it in GitHub Desktop.
reverse array with pop
This file contains 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
/** | |
* @param {array} array | |
*/ | |
function reverse(array) { | |
var res = []; | |
for (var i = array.length-1 ; i >= 0; i--) { | |
res.push(array.pop()); | |
} | |
return res; | |
} | |
console.log(reverse([1,2,3])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment