Skip to content

Instantly share code, notes, and snippets.

@dinocarl
Last active October 4, 2017 23:11
Show Gist options
  • Save dinocarl/f32812e012b615a5196e58ffe891f2cf to your computer and use it in GitHub Desktop.
Save dinocarl/f32812e012b615a5196e58ffe891f2cf to your computer and use it in GitHub Desktop.
// 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