Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add `mode()` aggregation function to find most common unique value.

Aperta
#5,864 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@lx3133584 ci sta già lavorando.

Dal 28/8/2026.

  • #6578 di @lx3133584 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
data

Direzione di ricerca

Inizia esaminando le API delle funzioni di aggregazione e l'esempio StackBlitz collegato nell'issue, incluso mode.test.ts. Aggiungi mode() come funzione di aggregazione disponibile, mantenendo il primo valore in caso di parità, e assicurati che i test unitari coprano il comportamento descritto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The statistical mode is a very common metric for data and very useful with nominal/categorical data. For example, say a table is of days with categories ["Sunny", "Cloudy", "Rainy"] -- knowing most days are "Rainy" is more useful than using unique() and knowing that the weather can be those categories.

A rough implementation of one can be seen below. The reason for the weird Array.from(counts).find(...) is that most implementations of mode from what I can tell tend to prefer finding the first element with the maximum count when there is a tie. I am open to other implementations if this isn't a concern.

const mode: AggregationFn<any> = (columnId, leafRows) => {
  if (!leafRows.length) {
    return
  }

  let maxCount = 0
  const counts = leafRows.reduce((counts, row) => {
    const value = row.getValue(columnId)
    const valueCount = (counts.get(value) ?? 0) + 1
    maxCount = Math.max(maxCount, valueCount)
    return counts.set(value, valueCount)
  }, new Map<unknown, number>())

  return Array.from(counts).find(([, count]) => count === maxCount)![0]
}

And here is a StackBlitz implementation showing it passes unit tests.

Lingua principale
TypeScript
Stelle
28.5k
Fork
3.6k
Merge medio
17h 39m
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/table

Tutte le issue di TanStack/table

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.