Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#62

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) {
        last--;
      } else if (this[index] == null) {
        this[index++] = this[last--];
      } else {
        index++;
      }
    }
    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.)

Reported by matthuhiggins · April 29th, 2008 @ 07:13 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Frederick Cheung
  2. matthuhiggins
    matthuhiggins

    I added this ticket over at prototype.lighthouse. I do not have privileges to close this one.

    April 29th, 2008 @ 08:28 PM

  3. DHH
    DHH
    • State changed from new to resolved

    April 30th, 2008 @ 09:40 PM