Javascript Array collect(operation)

Description

Javascript Array collect(operation)


// operation is a method that accepts one parameter and returns a value.
Array.prototype.collect = function(operation) {
    var derivedArray = [];
    for (i = 0; i < this.length; i += 1) {
        derivedArray.push(operation(this[i]));
    }/*from  ww w. j  a v a2 s  .c  o m*/
    return derivedArray;
}



PreviousNext

Related