//sample solution
function reverse(arr) {
//your code here
var startIndex = 0;
var endIndex = arr.length-1;
while(startIndex<endIndex){
swap(arr,startIndex,endIndex);
startIndex++;
endIndex--;
}
return arr;
}
function swap(arr, pos1, pos2) {
//your code here
var temp = arr[pos1];
arr[pos1] = arr[pos2];
arr[pos2] = temp;
}
//test
reverse([1,2,3,4]);
No comments:
Post a Comment