Created
September 27, 2018 08:18
-
-
Save manjunatha-d/e05ed5932f78fedd27619099899357b2 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
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