I don't understand why return weights_data returns undefined, and console.log(weights_data) returns something.
const getWeightReattributeProportionally = (weights_data, weight, z = 0) => {
weights_data.forEach( (r, i) => weights_data[i] = (r * weight) + r );
if ( weights_data.reduce( (a, b) => a + b) >= 0.9999999999999999 ) {
console.log(weights_data);
return weights_data;
} else {
getWeightReattributeProportionally(weights_data, weight *= weight, z += 1);
}
}
const data = [0.12, 0.22, 0.32, 0.18]
const aaaa = getWeightReattributeProportionally(data, 0.16)
console.log(aaaa)