import isArr from './isArr';
import deepCopy from './deepCopy';

/**
 * 去除对象的部分属性创建一个新对象
 * @param {Object} object
 * @param {Array} props
 * @param {boolean} isDeep
 * @returns
 *
 * @example
 * const mrTom = {
 *   name: 'Tom',
 *   age: 20,
 *   gender: 'male',
 *   hobby: ['reading', 'running'],
 * }
 * omit(mrTom, ['gender', 'hobby']); // => {name: 'Tom', age: 20}
 */
function omit(object, props, isDeep) {
  object = object || {};
  if (!isArr(props)) props = [];
  var obj = {};
  Object.keys(object).forEach(function (prop) {
    if (props.indexOf(prop) === -1) {
      obj[prop] = isDeep ? deepCopy(object[prop]) : object[prop];
    }
  });
  return obj;
}

export default omit;
