#62 enhancement

Add in place versions of compact, uniq, flatten to Array.prototype

Reported by matthuhiggins | April 29th, 2008 @ 09:26 PM

Given that prototype is modeled after Ruby, it seems like the in place '!' versions of these functions are missing. Since Array.prototype.reverse already takes an optional 'inline' parameter, it seems inconsistent that these other functions do not support it.

Let me try to hand type a rough version in this little text box:

_compact: function() {

var index = 0, last = this.length - 1;

while(index <= last) {

if (this[last] == null) {


} else if (this[index] == null) {

this[index++] = this[last--];

} else {




this.length = last + 1;

return this;


compact: function(inline) {

return (inline !== false ? this : this.toArray())._compact();



(Apologies if I am bringing up an old subject that has already been shot down.)

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins