Last active
August 27, 2016 15:10
-
-
Save harryadel/d4341b71094153850f7703a24134e215 to your computer and use it in GitHub Desktop.
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
/* | |
My answer for exercise 'Reversing an array' | |
in Eloquent JavaScript Second Edition | |
Chapter 4 Data Structures: Objects and Arrays | |
*/ | |
function reverseArray(array) { | |
var output = []; | |
for (var i = array.length - 1; i >= 0; i--) { | |
output += array[i]; | |
} | |
return output.split(""); | |
} | |
function reverseArrayInPlace(array) { | |
array.sort(function(a, b){return b-a}); | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment