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));
e,d,c,b,a
Very good.
ReplyDelete