Last active
October 4, 2017 23:11
-
-
Save dinocarl/f32812e012b615a5196e58ffe891f2cf to your computer and use it in GitHub Desktop.
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
// data | |
const types = [ | |
'typeA', | |
'typeB', | |
'typeC', | |
'all', | |
'typeD' | |
]; | |
const a = ['a', 'b', 'c', 'd']; | |
const b = ['e', 'f']; | |
// replace with lodash/fp variations as imports | |
const compose = _.flowRight; | |
const fpPartition = _.curry( (pred, arr) => _.partition(arr, pred) ); | |
const isAllPredicate = (item) => _.eq(item, 'all'); | |
const splitAtAllItem = fpPartition(isAllPredicate); | |
const allItemAtTop = compose([ | |
_.flatten, | |
splitAtAllItem, | |
_.concat | |
]); | |
allItemAtTop(types, a, b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment