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

Add `mins` and `maxes` TypeScript goodies

オープン
#178 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement typescript
主要言語
TypeScript
スター
20
フォーク
12
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。