var _ = require('lodash');
(function(){
    /**
     * Indexed Collection Constructor
     * @constructor
     */
    function IndexedCollection(){
        this.vector = [];
        this.index = {};
        Object.defineProperty(this, 'length', {
            get: function () {
                return this.vector.length
            }
        });
    }

    /**
     * Add new item
     * @param {Object} data
     */
    IndexedCollection.prototype.add = function (data) {
        if (!data.id) {
            throw new Error('No ID informed to IndexedCollection.prototype.add');
        }
        if (this.index[data.id]) {
            return this.edit(data.id, data);
        }
        var itemIndex = this.vector.push(data);
        this.index[data.id] = itemIndex - 1;
        return itemIndex;
    }

    /**
     * Find an item by subitems matching
     * @param  {Mixed} query Can be a string or object
     */
    IndexedCollection.prototype.find = function (subject) {
        var query;
        if (typeof subject == string || typeof subject == number) {

        }
    }

    /**
     * Find an item by ID
     * @param  {String} id
     * @return {Object}
     */
    IndexedCollection.prototype.findById = function (id) {
        var idx = this.index[id];
        return this.vector[idx];
    }

    /**
     * Edit a item's data recusively
     * @param  {String} id
     * @param  {Object} data
     * @return {Boolean} true if edition is done
     */
    IndexedCollection.prototype.edit = function (id, data) {
        var idx = this.index[id];
        if (!this.vector[idx]) {
            throw new Error('Item not found');
        }
        this.vector[idx] = _.merge(data, this.vector[idx]);
        return true;
    }

    /**
     * Remove an item
     * @param  {String} id
     */
    IndexedCollection.prototype.remove = function (id) {
        var idx = this.index[id];
        delete this.vector[idx];
        delete this.index[id];
        this._rebuildIndex();
    }

    IndexedCollection.prototype._rebuildIndex = function () {
        for (var i = 0; i < this.vector.length; i++) {
            this.vector[i]
        };
    }

    this.IndexedCollection = IndexedCollection;
}).call(this);

@@ -141,208 +141,36 @@
 tion
-()%7B%0A        this.vector = %5B%5D;%0A        this.index = %7B%7D;%0A        Object.defineProperty(this, 'length', %7B%0A            get: function () %7B%0A                return this.vector.length%0A            %7D%0A        %7D)
+ () %7B%0A        this.data = %7B%7D
 ;%0A  
@@ -423,29 +423,28 @@
    if (this.
-index
+data
 %5Bdata.id%5D) %7B
@@ -511,117 +511,33 @@
     
-var itemIndex = this.vector.push(data);%0A        this.index%5Bdata.id%5D = itemIndex - 1;%0A        return itemIndex
+this.data%5Bdata.id%5D = data
 ;%0A  
@@ -974,42 +974,8 @@
 ) %7B%0A
-        var idx = this.index%5Bid%5D;%0A
     
@@ -986,30 +986,28 @@
 return this.
-vector
+data
 %5Bidx%5D;%0A    %7D
@@ -1231,42 +1231,8 @@
 ) %7B%0A
-        var idx = this.index%5Bid%5D;%0A
     
@@ -1245,26 +1245,23 @@
  (!this.
-vector
+data
 %5Bid
-x
 %5D) %7B%0A   
@@ -1327,26 +1327,23 @@
    this.
-vector
+data
 %5Bid
-x
 %5D = _.me
@@ -1357,26 +1357,23 @@
 a, this.
-vector
+data
 %5Bid
-x
 %5D);%0A    
@@ -1530,288 +1530,28 @@
     
-var idx = this.index%5Bid%5D;%0A        delete this.vector%5Bidx%5D;%0A        delete this.index%5Bid%5D;%0A        this._rebuildIndex();%0A    %7D%0A%0A    IndexedCollection.prototype._rebuildIndex = function () %7B%0A        for (var i = 0; i %3C this.vector.length; i++) %7B%0A            this.vector%5Bi%5D%0A        %7D
+delete this.data%5Bid%5D
 ;%0A  

Use only a internal data object