Pages

Thursday, December 23, 2010

JS - Reverse Order

/**
 * Order Reversing
 * @author : irfanudin ridho
 * @email  : irfan.ub@gmail.com
 * @date   : December 24, 2010
 * @version: 1.0
 *
 * This class provide method for reversing the order of an array
 *
 * @param array data for sorting
 */ 

function Reverse(arr){
    var k = 0;  
    this.reversedData = new Array();
    for(i=(arr.length)-1;i>=0;i--){
        this.reversedData[k] = arr[i];
        k = k + 1;
    }
}

/**
 * @return Array reversed order
 */
Reverse.prototype.getRev = function(){
    return this.reversedData;
};

No comments:

Post a Comment