Created
November 24, 2020 16:26
-
-
Save oleggrishechkin/1bf883fedfeef7b33f9a043ff4446d09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stringCheck = (keyToOmit) => (value, key) => keyToOmit === key; | |
const arrayOfStringCheck = (keysToOmit) => (value, key) => keysToOmit.includes(key); | |
const omit = (targetObject, options) => { | |
const check = typeof options === 'function' ? options : Array.isArray(options) ? arrayOfStringCheck : stringCheck; | |
return Object.keys(targetObject).reduce((result, key) => { | |
if (!check(targetObject[key], key, targetObject)) { | |
result[key] = targetObject[key]; | |
} | |
return result; | |
}, {}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment