code-chronicles-code / code-chronicles-code/leetcode-curriculum

Add `mins` and `maxes` TypeScript goodies

Open
#178 0 comments 0 reactions 0 assignees View on GitHub
enhancement typescript
Dominant language
TypeScript
Stars
20
Forks
12
PR merge metrics
No merged PRs in 30d

Description

The Ruby [min](https://apidock.com/ruby/Enumerable/min) and [max](https://apidock.com/ruby/Enumerable/max) methods allow specifying an argument, to get more than one minimum or maximum. I think it'd be fun to add a goody for this, but rather than modifying `Iterator.prototype.min` and/or `Iterator.prototype.max`, I think we should have new goodies for this, since it's a somewhat niche need.

I'm proposing `Iterator.prototype.mins` and `Iterator.prototype.maxes` as the names for these, although other suggestions are welcome.

For the implementation, `BinaryHeap` would be fun to use. It will be easiest to start with `.maxes` (since the default behavior of the heap is as a min-heap, and we can use `compareNatural` goody as the default comparator). For `.mins`, it will be necessary to come up with a way to reverse the comparator.

Additional note: `min` and `max` handle NaN specially. We can skip that behavior to start with for `.mins` and `.maxes`, and come back to it later.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.