ee44a25bf9d08a606471d9b9175d1a8867292998
[platform/framework/web/crosswalk-tizen.git] /
1
2
3     /**
4      * Array lastIndexOf
5      */
6     function lastIndexOf(arr, item, fromIndex) {
7         if (arr == null) {
8             return -1;
9         }
10
11         var len = arr.length;
12         fromIndex = (fromIndex == null || fromIndex >= len)? len - 1 : fromIndex;
13         fromIndex = (fromIndex < 0)? len + fromIndex : fromIndex;
14
15         while (fromIndex >= 0) {
16             // we iterate over sparse items since there is no way to make it
17             // work properly on IE 7-8. see #64
18             if (arr[fromIndex] === item) {
19                 return fromIndex;
20             }
21             fromIndex--;
22         }
23
24         return -1;
25     }
26
27     module.exports = lastIndexOf;
28