All files / arr erase.js

100% Statements 5/5
50% Branches 1/2
100% Functions 1/1
100% Lines 5/5

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                        13x 13x 13x   13x     3x  
/**
 * 删除数组中的对象
 * @method arr/erase
 * @param {Array} arr 要操作的数组
 * @param {*} item 要清除的对象
 * @returns {Number} 对象原本所在位置
 * @example
 * var $erase = require('@spore-ui/kit/packages/arr/erase');
 * console.info($erase([1,2,3,4,5],3)); // [1,2,4,5]
 */
 
function erase(arr, item) {
  var index = arr.indexOf(item);
  Eif (index >= 0) {
    arr.splice(index, 1);
  }
  return index;
}
 
module.exports = erase;