// collector.js v1
// by Matt Sacks <matt.s.sacks@gmail.com>

;(function() {
  "use strict";

  // loops over an array of data and applies a mapping function for each item in
  // the array. after each mapping is applied, a rolling reduction is then
  // called onto the datum.
  // 
  // - **data** (Array): array of data to call mappings and reductions onto
  // - **maps** (Object): an object where each key is an object of a map:
  // and/or reduce: function that will be called on each datum
  // - **options** (Object): options, but none exist yet
  function collect(data, maps, options) {
    if (data == null || data.length === 0 || maps == null) return {};

    // the returned object
    var collection = {};

    var isArray = Array.isArray || function isArray(item) {
      return item.toString() == '[object Array]';
    };

    if (isArray(data)) {
      for (var i = 0, len = data.length; i < len; i++) {
        mapreduce(data[i], i);
      }
    }
    else {
      for (var id in data) {
        mapreduce(data[id], id);
      };
    }

    function mapreduce(datum, i) {
      for (var key in maps) {
        var mapreduce = maps[key];
        var map = mapreduce.map;
        var reduce = mapreduce.reduce;

        if (map == null) return;

        var rolling = collection[key];
        var result = map(datum, i);

        collection[key] = collection[key] || [];
        return reduce == null ?
          collection[key].push(result) :
          collection[key] = reduce(rolling, result, datum, id);
      }
    };

    return collection;
  };

  typeof exports == 'undefined' ?
    window.collect = collect :
    module.exports = collect;
})();

@@ -1047,16 +1047,371 @@
 %0A    %7D%0A%0A
+    // for each key available in maps, call the map and/or reduce function%0A    // found on the datum%0A    //%0A    // - **datum** (): Any non-null item to call each mapreduce function on.%0A    // - **i** (): If the data is an Array, then it will be the datum's index.%0A    // Otherwise, if the data is an Object, it will be the key for the datum%0A    // value.%0A
     func
@@ -1867,17 +1867,16 @@
 datum, i
-d
 );%0A     

comment mapreduce(), fix 4th argument of reduce