Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.pluck #1064

Merged
merged 1 commit into from Nov 4, 2011
Merged

Array.pluck #1064

merged 1 commit into from Nov 4, 2011

Conversation

ghost
Copy link

@ghost ghost commented Nov 4, 2011

Good complement to Array.invoke, this method is in Prototype and ExtJS (off the top of my head; there could be others).

@cpojer
Copy link
Member

cpojer commented Nov 4, 2011

Sure whynot.

cpojer added a commit that referenced this pull request Nov 4, 2011
@cpojer cpojer merged commit df02433 into mootools:master Nov 4, 2011
@arian
Copy link
Member

arian commented Nov 4, 2011

Very nice!

Alternative implementation without relying on .map and function calls, which should be a bit faster:

Array.implement({

    pluck: function(property){
        var length = this.length >>> 0, results = new Array(length);
        for (var i = 0; i < length; i++){
            if (i in this) results[i] = this[i][property];
        }
        return results;
    }

});

jsperf: http://jsperf.com/pluck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants