Skip to content

Commit

Permalink
задачи с pick и omit
Browse files Browse the repository at this point in the history
  • Loading branch information
TimofeevAnton1980 committed Nov 8, 2024
1 parent 8e431f6 commit f48ace4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion 02-javascript-data-types/2-pick/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {});
};
7 changes: 6 additions & 1 deletion 02-javascript-data-types/3-omit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {});
};

0 comments on commit f48ace4

Please sign in to comment.