Solución
solution.tsTypeScript
export function weightedAverage(values: number[], weights: number[]): number {
// v1*w1 + v2*w2 + ... + vn*wn
const weightedSum = values.reduce((prev, curr, index) => prev + curr * weights[index], 0)
// w1 + w2 + ... + wn
const totalWeigth = weights.reduce((prev, curr) => prev + curr, 0)
return weightedSum / totalWeigth
}0respuestas