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

Add `mins` and `maxes` TypeScript goodies

Abierto
#178 0 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement typescript
Lenguaje dominante
TypeScript
Estrellas
20
Forks
12
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.