Skip to content

Instantly share code, notes, and snippets.

@GabrielNicolasAvellaneda
Created July 9, 2018 18:38
Show Gist options
  • Save GabrielNicolasAvellaneda/e219423f3cdc99d30b2821271bccd57c to your computer and use it in GitHub Desktop.
Save GabrielNicolasAvellaneda/e219423f3cdc99d30b2821271bccd57c to your computer and use it in GitHub Desktop.
const partition = (list, partitioner) => {
const toIndex = (el) => (partitioner(el)) ? 0 : 1;
const toPartition = (result, el) => {
result[toIndex(el)].push(el)
return result;
}
return list.reduce(toPartition, [[],[]]);
}
partition([1, 2, 3, 4], n => n % 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment