/**
 * omit.js
 *
 * @Author: jruif
 * @Date: 2017/6/29 下午3:44
 */
import assign from 'object-assign';
import { isFunction } from './isType';
/*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
* omit(object, ['a', 'c']); // => { 'b': '2' }
*
* */

function omit(obj, fields) {
  var copy = assign({}, obj);

  if (Array.isArray(fields)) {
    for (var i = 0; i < fields.length; i++) {
      var key = fields[i];
      delete copy[key];
    }
  } else if (isFunction(fields)) {
    for (var _key in copy) {
      if (copy.hasOwnProperty(_key) && fields(copy[_key])) {
        delete copy[_key];
      }
    }
  }

  return copy;
}

export default omit;