Created
December 31, 2020 05:08
-
-
Save unicornware/8c15def16d9ec399872bfee7e4ec8e3e to your computer and use it in GitHub Desktop.
Reduce an array of objects into a single object
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
| import { merge } from 'lodash' | |
| /** | |
| * @file Implementation - reduceObjects | |
| * @author Lexus Drumgold <[email protected]> | |
| */ | |
| type AnyObject = Record<string, any> | |
| /** | |
| * Merges an array of objects into a single object. | |
| * | |
| * @param args - Objects to merge | |
| */ | |
| const reduceObjects = (...args: AnyObject[]): AnyObject => { | |
| const reducer = (acc: AnyObject, curr: AnyObject) => merge(acc, curr) | |
| return (args || []).reduce(reducer, {}) | |
| } | |
| export default reduceObjects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment