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

Add `mins` and `maxes` TypeScript goodies

Đang mở
#178 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement typescript
Ngôn ngữ chính
TypeScript
Star
20
Fork
12
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.