Squashed commit of the following:
commit 4810de3b94b0ec0d7e9b8570de58f85792dffa80 Author: GuillaumeSD <gsd.lfny@gmail.com> Date: Sat Apr 6 01:37:42 2024 +0200 fix : lint commit 59e0b571e6089da6c086ab6340ec6a966b2e9739 Author: GuillaumeSD <gsd.lfny@gmail.com> Date: Sat Apr 6 01:36:17 2024 +0200 feat : UI refacto commit 56806a89dca5c7fb2c229b5a57404f9a856fac09 Author: GuillaumeSD <gsd.lfny@gmail.com> Date: Fri Apr 5 03:56:08 2024 +0200 feat : add moves list commit 9e3d2347882074c38ab183e642ecef8153dbfcde Author: GuillaumeSD <gsd.lfny@gmail.com> Date: Thu Apr 4 02:18:52 2024 +0200 feat : init branch, wip
This commit is contained in:
@@ -6,36 +6,10 @@ export const capitalize = (s: string) => {
|
||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||
};
|
||||
|
||||
export const ceilsNumber = (number: number, min: number, max: number) => {
|
||||
if (number > max) return max;
|
||||
if (number < min) return min;
|
||||
return number;
|
||||
};
|
||||
|
||||
export const getHarmonicMean = (array: number[]) => {
|
||||
const sum = array.reduce((acc, curr) => acc + 1 / curr, 0);
|
||||
return array.length / sum;
|
||||
};
|
||||
|
||||
export const getStandardDeviation = (array: number[]) => {
|
||||
const n = array.length;
|
||||
const mean = array.reduce((a, b) => a + b) / n;
|
||||
return Math.sqrt(
|
||||
array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n
|
||||
export const isInViewport = (element: HTMLElement) => {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return (
|
||||
rect.top >= 0 &&
|
||||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
|
||||
);
|
||||
};
|
||||
|
||||
export const getWeightedMean = (array: number[], weights: number[]) => {
|
||||
if (array.length > weights.length)
|
||||
throw new Error("Weights array is too short");
|
||||
|
||||
const weightedSum = array.reduce(
|
||||
(acc, curr, index) => acc + curr * weights[index],
|
||||
0
|
||||
);
|
||||
const weightSum = weights
|
||||
.slice(0, array.length)
|
||||
.reduce((acc, curr) => acc + curr, 0);
|
||||
|
||||
return weightedSum / weightSum;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user