Code coverage report for array/min.js

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

All files » array/ » min.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 24 12 12 4   8     8 24 24 16 16     8       1      
define(['./forEach'], function (forEach) {
 
    /**
     * Return minimum value inside array
     */
    function min(arr, iterator){
        if (arr.length && !iterator) {
            return Math.min.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 min;
 
});