Skip to content

Conversation

@lionel-rowe
Copy link

function chunk(input, size) {
  return Object.values(
    Object.groupBy(input, (_, i) => Math.floor(i / size))
  );
}

function countBy(input, fn) {
  return Object.fromEntries(
    Object.entries(Object.groupBy(input, fn)).map(([k, v]) => [k, v.length])
  );
}

function partition(input, fn) {
  const results = Object.groupBy(input, (x) => Boolean(fn(x)))
  return [results.true ?? [], results.false ?? []]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant