All files / arr include.js

100% Statements 5/5
100% Branches 2/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 22 23                        1x     2x 1x   2x     1x  
/**
 * 确认对象是否在数组中,不存在则将对象插入到数组中
 * @method arr/include
 * @param {Array} arr 要操作的数组
 * @param {*} item 要插入的对象
 * @returns {Array} 经过处理的源数组
 * @example
 * var $include = require('@spore-ui/kit/packages/arr/include');
 * console.info($include([1,2,3],4)); // [1,2,3,4]
 * console.info($include([1,2,3],3)); // [1,2,3]
 */
 
var $contains = require('./contains');
 
function include(arr, item) {
  if (!$contains(arr, item)) {
    arr.push(item);
  }
  return arr;
}
 
module.exports = include;