Code coverage report for object/reduce.js

Statements: 100% (13 / 13)      Branches: 100% (6 / 6)      Functions: 100% (4 / 4)      Lines: 100% (12 / 12)     

All files » object/ » reduce.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291         1 14   14 2     12 38 4 4     34       12     1      
define(['./forOwn', './size'], function(forOwn, size) {
 
    /**
     * Object reduce
     */
    function reduce(obj, callback, memo, thisObj) {
        var initial = arguments.length > 2;
 
        if (!size(obj) && !initial) {
            throw new Error('reduce of empty object with no initial value');
        }
 
        forOwn(obj, function(value, key, list) {
            if (!initial) {
                memo = value;
                initial = true;
            }
            else {
                memo = callback.call(thisObj, memo, value, key, list);
            }
        });
 
        return memo;
    }
 
    return reduce;
 
});