underscore.js 源码分析
sortedIndex  findIndex  findLastIndex rangesortedIndex
sortedIndex(list, value, [iteratee], context)其中 list 是已经被排好序的数组,通过使用 soetedIndex 可以查找到 value 在已经排好序的 list 数组中的顺序。使用 二分法进行查找的。使用二分法进行查找的 value 位置如下:| 1 | function sortIndex(array, obj, iteratee, context) { | 
findIndex
findIndex(array, predicate, [context])返回在array 中满足 predicate 函数为真的第一个元素的索引, 如果没有找到,返回 -1;findLastIndex
类似于使用 findIndex 不同的是从数组的从后向前开始检索,返回的是第一个判断为真的值使用 findIndex 以及 findLastIndex 的代码如下:| 1 | function getIndexFunc(dir) { | 
range
range([start], stop, [step])使用 range 创建一个整数灵活编号的列表函数,返回一个从 start 到 stop 的整数的一个列表, 通过使用 step 来减少独占。如果省略 start, start 默认从 0 开始,步进为 1;自己写的代码:| 1 | function range(start, stop, step) { | 
| 1 | /* |