Skip to content

Instantly share code, notes, and snippets.

@hejrobin
Created December 12, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hejrobin/b40fa050fda3149b0ceaa69c25f4ad8a to your computer and use it in GitHub Desktop.
Save hejrobin/b40fa050fda3149b0ceaa69c25f4ad8a to your computer and use it in GitHub Desktop.
/* @flow */
/* @type-dependencies */
import type MixedObjectType from './generics';
export default function dissect( sourceObject : MixedObjectType, ...dissectKeys : Array<string> ) : [ MixedObjectType, MixedObjectType ] {
const remainingObject : MixedObjectType = {};
const dissectedObject : MixedObjectType = {};
for ( const [ key, value ] of Object.entries( sourceObject ) ) {
if ( dissectKeys.includes( key ) ) {
dissectedObject[ key ] = value;
} else {
remainingObject[ key ] = value;
}
}
return [ dissectedObject, remainingObject ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment