UNPKG

redux

Version:

Predictable state container for JavaScript apps

16 lines (15 loc) • 467 B
/** * Picks key-value pairs from an object where values satisfy a predicate. * * @param {Object} obj The object to pick from. * @param {Function} fn The predicate the values must satisfy to be copied. * @returns {Object} The object with the values that satisfied the predicate. */ export default function pick(obj, fn) { return Object.keys(obj).reduce((result, key) => { if (fn(obj[key])) { result[key] = obj[key] } return result }, {}) }