Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 6x 2x 1x 1x | /**
 * 查找符合条件的元素在数组中的位置
 * @method arr/find
 * @param {Array} arr 要操作的数组
 * @param {Function} fn 条件函数
 * @param {Object} [context] 函数的this指向
 * @return {Array} 符合条件的元素在数组中的位置
 * @example
 * var $find = require('@spore-ui/kit/packages/arr/find');
 * console.info($find([1,2,3,4,5], function (item) {
 *   return item < 3;
 * }); // [0, 1]
 */
 
function findInArr(arr, fn, context) {
  var positions = [];
  arr.forEach(function (item, index) {
    if (fn.call(context, item, index, arr)) {
      positions.push(index);
    }
  });
  return positions;
}
 
module.exports = findInArr;
  |