Add `mode()` aggregation function to find most common unique value.
維護者通常 1 天內回覆
評估
- 難度
- 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
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/table 的其他 Issue
-
Issue template renders `react-table`, not `TanStack/table`可能已有人在做 @vishruthasgowda 於 15 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 78/100
維護者通常 1 天內回覆
-
table-core 9.2.5+: private types leak from .d.ts files, declaration emit fails with TS2883可能已有人在做 @MFA-G 今天認領。 未關閉
難度 3/5 1-2 天 新手友好度 74/100
維護者通常 1 天內回覆
-
[svelte] createTableHook: App* wrappers call setContext in the parent's component context (set_context_after_init when showing a column)可能已有人在做 @india3Eth 於 1 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 68/100
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 38/100
維護者通常 1 天內回覆
-
Cast required to access custom options when defining a custom plugin/feature可能已有人在做 @sorena-paydar 於 16 天前認領。 未關閉
難度 5/5 一週以上 新手友好度 35/100
維護者通常 1 天內回覆
相似的 Issue
-
component:sight
難度 2/5 1-3 小時 新手友好度 78/100
agentic-os-org/ANOLISA#6738 · 2 則留言 ·
維護者通常 1 天內回覆
-
bug Durable Agents Observability (AI Telemetry) status: needs triage
難度 2/5 1-3 小時 新手友好度 82/100
mastra-ai/mastra#26470 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
paperclipai/paperclip#15630 ·
維護者通常 1 天內回覆
-
[good first issue, hacktoberfest] ⛩️ Add new Theme: Sakura Latte (good-first-issue)可能已有人在做 @PGrayCS 今天認領。 未關閉community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難度 1/5 1-3 小時 新手友好度 78/100
lingdojo/kana-dojo#31937 · 1 則留言 · 5 個 reaction ·
維護者通常 1 天內回覆
-
feature/cohorts feature/feature-flags team/feature-flags
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆