Created
February 28, 2020 09:59
-
-
Save jaouadballat/2e9cbeac16cda959a301827f34d04fd2 to your computer and use it in GitHub Desktop.
This file contains 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
function omit(object, fields) { | |
const shallowObject = Object.assign({}, object); | |
if (typeof fields === Array) { | |
fields.forEach(field => { | |
if (!!shallowObject[field]) delete shallowObject[field]; | |
}); | |
return shallowObject; | |
} else if (typeof fields === "string") return delete shallowObject[fields]; | |
else throw new Error(`fields ${fields} must be array or string`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment