diff --git a/snippets/omit.md b/snippets/omit.md new file mode 100644 index 000000000..4036a8d9e --- /dev/null +++ b/snippets/omit.md @@ -0,0 +1,17 @@ +### omit + +Omits the key-value pairs corresponding to the given keys from an object. + +Use `Object.keys(obj)`, `Array.filter()` and `Array.includes()` to remove the provided keys. +Use `Array.reduce()` to convert the filtered keys back to an object with the corresponding key-value pairs. + +```js +const omit = (obj, arr) => + Object.keys(obj) + .filter(k => !arr.includes(k)) + .reduce((acc, key) => ((acc[key] = obj[key]), acc), {}); +``` + +```js +omit({ a: 1, b: '2', c: 3 }, ['b']); // { 'a': 1, 'c': 3 } +``` diff --git a/snippets/pick.md b/snippets/pick.md index 3e6894f79..4c9801da7 100644 --- a/snippets/pick.md +++ b/snippets/pick.md @@ -2,7 +2,7 @@ Picks the key-value pairs corresponding to the given keys from an object. -Use `Array.reduce()` to convert the filtered/picked keys back to an object with the corresponding key-value pair if the key exists in the obj. +Use `Array.reduce()` to convert the filtered/picked keys back to an object with the corresponding key-value pairs if the key exists in the object. ```js const pick = (obj, arr) => diff --git a/tag_database b/tag_database index 3796ee84a..d9b8cf764 100644 --- a/tag_database +++ b/tag_database @@ -131,6 +131,7 @@ objectFromPairs:object,array objectToPairs:object,array observeMutations:browser,event,advanced off:browser,event +omit:object,array on:browser,event once:function onUserInputChange:browser,event,advanced @@ -139,7 +140,7 @@ palindrome:string parseCookie:utility,string partition:array,object,function percentile:math -pick:array +pick:object,array pipeFunctions:adapter,function pluralize:string powerset:math