Download node_modules/d3-array/src/mode.js from NKessler/Horizon: direct link, hf CLI and curl.
- Browser
- Download file 708 Bytes
-
https://huggingface.co/NKessler/Horizon/resolve/main/node_modules/d3-array/src/mode.js
- Command line
-
hf download hf://NKessler/Horizon/node_modules/d3-array/src/mode.js
-
curl -L -o mode.js https://huggingface.co/NKessler/Horizon/resolve/main/node_modules/d3-array/src/mode.js
708 Bytes
| import {InternMap} from "internmap"; | |
| export default function mode(values, valueof) { | |
| const counts = new InternMap(); | |
| if (valueof === undefined) { | |
| for (let value of values) { | |
| if (value != null && value >= value) { | |
| counts.set(value, (counts.get(value) || 0) + 1); | |
| } | |
| } | |
| } else { | |
| let index = -1; | |
| for (let value of values) { | |
| if ((value = valueof(value, ++index, values)) != null && value >= value) { | |
| counts.set(value, (counts.get(value) || 0) + 1); | |
| } | |
| } | |
| } | |
| let modeValue; | |
| let modeCount = 0; | |
| for (const [value, count] of counts) { | |
| if (count > modeCount) { | |
| modeCount = count; | |
| modeValue = value; | |
| } | |
| } | |
| return modeValue; | |
| } | |