nodejs : recurvive function return undefined

  javascript, node.js

I don’t understrand why the "return weights_data" return undefined and the "console.log(weights_data)" return 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)

Source: Ask Javascript Questions

LEAVE A COMMENT