Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created January 12, 2026 12:31
Show Gist options
  • Select an option

  • Save goofballLogic/c024fd104a8685bc2a99c7e2c45a13c8 to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/c024fd104a8685bc2a99c7e2c45a13c8 to your computer and use it in GitHub Desktop.
const hungryBears = bears =>
bears
.map(x => ({ ...x })) // avoid tainting the inputs
.sort((a, b) =>
(a.visited = a.visited || (bears.sum = (bears.sum || 0) + a.hunger) || true)
&&
(b.visited = b.visited || (bears.sum = (bears.sum || 0) + b.hunger) || true)
&&
(a.name > b.name ? 1 : a.name < b.name ? -1 : 0))
.filter(b => b.hunger > bears.sum / bears.length)
.map(b => b.name)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment