Create your own array reverse() method in JavaScript


Took 21 minutes and 22 seconds to create array reverse() method in JavaScript. Here is the code snippet.

Code:
var arr = ['a', 'b', 'c', 'd', 'e'];

function reverse(arr) {
var arr2 = [];
var i = arr.length-1;
while (i >= 0) {
arr2.push(arr[i]);
i--;
}
return arr2;
}

document.write(reverse(arr));

Result:
e,d,c,b,a

1 comment:

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...