Created
January 12, 2026 12:31
-
-
Save goofballLogic/c024fd104a8685bc2a99c7e2c45a13c8 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
| 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