79341654

Date: 2025-01-09 07:10:21
Score: 0.5
Natty:
Report link

You can check the current value of loop in .map() and return 0 if the value is 0:

var arr = [1, 4.5, 0, 0, 3];
var sum = 0;

var result = arr.map(value => value ? sum += value : 0);

console.log(result);

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Lã Ngọc Hải