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

Add `mins` and `maxes` TypeScript goodies

Aperta
#178 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement typescript
Lingua principale
TypeScript
Stelle
20
Fork
12
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.