This commit is contained in:
Angelos Chalaris
2018-01-19 13:14:46 +02:00
parent 435260d6f4
commit 97192399e9
3 changed files with 20 additions and 2 deletions

17
snippets/omit.md Normal file
View File

@ -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 }
```

View File

@ -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) =>

View File

@ -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