diff --git a/02-javascript-data-types/2-pick/index.js b/02-javascript-data-types/2-pick/index.js index cecddf6..b70f009 100644 --- a/02-javascript-data-types/2-pick/index.js +++ b/02-javascript-data-types/2-pick/index.js @@ -5,5 +5,10 @@ * @returns {object} - returns the new object */ export const pick = (obj, ...fields) => { - + return Object.entries(obj).reduce((newPick, [key, value]) => { + if (fields.includes(key)) { + newPick[key] = value; + } + return newPick; + }, {}); }; diff --git a/02-javascript-data-types/3-omit/index.js b/02-javascript-data-types/3-omit/index.js index de2f0ee..c7ac658 100644 --- a/02-javascript-data-types/3-omit/index.js +++ b/02-javascript-data-types/3-omit/index.js @@ -5,5 +5,10 @@ * @returns {object} - returns the new object */ export const omit = (obj, ...fields) => { - + return Object.entries(obj).reduce((newPick, [key, value]) => { + if (!fields.includes(key)) { + newPick[key] = value; + } + return newPick; + }, {}); };