mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-09 07:41:35 +00:00
293c0b604d
* Add SVG icons for map pins * Add federation basis and new coordinator form (#793) * Add new coordinator entry issue form * Add Federation basis * Fix eslint errors from F2F and fix languages * Redo eslint @typescript-eslint/strict-boolean-expressions * Robot Page working * Contexts Working * Garage Working * CurrentOrder working * Federation model working --------- Co-authored-by: Reckless_Satoshi <reckless.satoshi@protonmail.com> Co-authored-by: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com>
17 lines
417 B
TypeScript
17 lines
417 B
TypeScript
export const weightedMean = (arrValues: number[], arrWeights: number[]): number => {
|
|
if (arrValues.length === 0) {
|
|
return 0;
|
|
}
|
|
const result = arrValues
|
|
.map((value, i) => {
|
|
const weight = arrWeights[i];
|
|
const sum = value * weight;
|
|
return [sum, weight];
|
|
})
|
|
.reduce((p, c) => [p[0] + c[0], p[1] + c[1]], [0, 0]);
|
|
|
|
return result[0] / result[1];
|
|
};
|
|
|
|
export default weightedMean;
|