Code coverage report for array/max.js

Statements: 100% (15 / 15)      Branches: 100% (8 / 8)      Functions: 100% (4 / 4)      Lines: 100% (14 / 14)     

All files » array/ » max.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 27 15 12 4   8     8 24 24 12 12     8       1      
define(['./forEach'], function (forEach) {
 
    /**
     * Return maximum value inside array
     */
    function max(arr, iterator){
        if (arr.length && !iterator) {
            return Math.max.apply(Math, arr);
        } else if (!arr.length) {
            return Infinity;
        } else {
            var result,
                compare = -Infinity,
                tmp;
            forEach(arr, function(val, i, list){
                tmp = iterator(val, i, list);
                if (tmp > compare) {
                    compare = tmp;
                    result = val;
                }
            });
            return result;
        }
    }
 
    return max;
 
});