Skip to content

Instantly share code, notes, and snippets.

@manjunatha-d
Created September 27, 2018 08:18
Show Gist options
  • Save manjunatha-d/e05ed5932f78fedd27619099899357b2 to your computer and use it in GitHub Desktop.
Save manjunatha-d/e05ed5932f78fedd27619099899357b2 to your computer and use it in GitHub Desktop.
export function splitArray<T>(
array: ReadonlyArray<T>,
predicate: (value: T) => boolean,
): _.Dictionary<ReadonlyArray<T>> {
return array.reduce(
(accu, value) => {
if (predicate(value)) {
return {
...accu,
truthyPart: [...accu.truthyPart, value],
};
}
return {
...accu,
falsyPart: [...accu.falsyPart, value],
};
},
// default value
{
truthyPart: [],
falsyPart: [],
},
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment