Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, December 7, 2012

LearnStreet Javascript Lesson 7 Exercise 4


//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


This is an example of scrolling text using Javascript.

Popular Posts