Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#5,864 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@lx3133584 已經在處理了。

開始於 2026年8月28日。

  • #6578 來自 @lx3133584 —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
45/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
typescript
領域
data

研究方向

先檢視彙總函式 API,以及 issue 中連結的 StackBlitz 範例,包括 mode.test.ts。將 mode() 新增為可用的彙總函式,在平手時保留第一個值,並確保單元測試涵蓋所述行為。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
TypeScript
星號
28.5k
分支
3.6k
平均合併
17 小時 39 分鐘
30 天內合併 PR
10

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/table 的其他 Issue

查看 TanStack/table 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。