Product of all gains except each index without division
An audio effects chain passes a signal through several stages, and each stage multiplies the signal by its own gain factor. The mixer has a bypass preview: hovering a stage shows the total gain of the chain as if that one stage were switched off. Implement gainWithoutStage(gains), which returns that preview value for every stage at once.
gainWithoutStage(gains) // => number[]
The value at index i of the result is the product of every gain in gains except gains[i].
0, so dividing the total by a stage’s gain does not work.-0. Where a product is zero, return 0.[1] (the product of no gains is 1). An empty chain returns [].gains.gainWithoutStage([2, 3, 4]);
// => [12, 8, 6]
gainWithoutStage([0.5, 4, 2]);
// => [8, 1, 2]
gainWithoutStage([3, 0, 2, 5]);
// => [0, 30, 0, 0] (bypassing the muted stage is the only way to hear anything)
gainWithoutStage([0, 4, 0, 2]);
// => [0, 0, 0, 0] (two muted stages)
gainWithoutStage([-2, 0, 3]);
// => [0, -6, 0] (0, not -0)
gainWithoutStage([7]);
// => [1]