'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = filter;

var _foreach;

function _load_foreach() {
  return _foreach = _interopRequireDefault(require('./foreach'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * create a new array with all elements that pass the test implemented by the provided function.
 * @name filter
 * @param {object} obj object or array to iterate 
 * @param {function} cb callback function to invoke
 * @example 
 * ```js
 *  filter({ a: 1, b: 2, c: 3 }, (val, key) => val === 1) // => { a: 1 }
 * ```
 */
function filter(obj, cb) {
  var newObj = {};

  (0, (_foreach || _load_foreach()).default)(obj, function (val, key) {
    if (cb(val, key)) newObj[key] = val;
  });

  return obj;
}