MCPcopy Index your code
hub / github.com/refined-github/refined-github / createHeatIndexFunction

Function createHeatIndexFunction

source/helpers/math.ts:29–44  ·  view source on GitHub ↗
(numbers: number[])

Source from the content-addressed store, hash-verified

27 @returns function to calculate heat index of a given number
28 */
29export function createHeatIndexFunction(numbers: number[]): (value: number) => number {
30 const steps = 10; // GH has 10 heat colors
31 const min = Math.min(...numbers);
32 const max = Math.max(...numbers);
33
34 return (value: number) => {
35 // Inverse linear interpolation figures out how far the value is between min & max
36 const interp = Math.max(0, Math.min(1, inverseLinearInterpolation(min, max, value)));
37
38 // Maps the [0.0, 1.0] value to [steps, 1]
39 const floored = Math.floor(interp * steps);
40 const heatIndex = Math.max(1, steps - floored);
41
42 return heatIndex;
43 };
44}
45
46export function randomArrayItem<T>(items: T[]): T {
47 return items.at(Math.floor(Math.random() * items.length))!;

Callers 2

addCountsFunction · 0.85
file-age-color.tsxFile · 0.85

Calls 1

Tested by

no test coverage detected