Javascript Array partition(fn)

Description

Javascript Array partition(fn)


Array.prototype.partition = function(fn) {
    var xs = [], ys = [], len = this.length, i, e;

    for (i = 0; i < len; i++) {
        e = this[i];/*from w  w w.  j  a  va2s . c om*/
        (fn(e) ? xs : ys).push(e);
    }

    return [xs, ys];
};

function unpack(fn, el)
{
    return fn.apply(null, el);
}



PreviousNext

Related