Code coverage report for array/lastIndexOf.js

Statements: 100% (12 / 12)      Branches: 100% (8 / 8)      Functions: 100% (3 / 3)      Lines: 100% (11 / 11)     

All files » array/ » lastIndexOf.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231         1 33 33 33 33     95 21   74   12     1    
define(function () {
 
    /**
     * Array lastIndexOf
     */
    function lastIndexOf(arr, item, fromIndex) {
        var len = arr.length;
        fromIndex = (fromIndex == null || fromIndex >= len)? len - 1 : fromIndex;
        fromIndex = (fromIndex < 0)? len + fromIndex : fromIndex;
        while (fromIndex >= 0) {
            // we iterate over sparse items since there is no way to make it
            // work properly on IE 7-8. see #64
            if (arr[fromIndex] === item) {
                return fromIndex;
            }
            fromIndex--;
        }
        return -1;
    }
 
    return lastIndexOf;
});