```
var maxProduct = function (nums) {
let f = 1, b = 1, res = nums[0];
for (let i = 0; i < nums.length; i++) {
const j = nums.length - 1 - i;
f = f * nums[i] || nums[i];
b = b * nums[j] || nums[j];
res = Math.max(res, f, b);
}
return res;
};
```