Once the loop as finished, I’ve assigned prev to reduced to act like Reduce’s final return value. We then re-assign prev each time and add + our next.price to it. From there, we’ll loop our items and create a next variable.
reduce (( prev, next, index, array ) => reduced = prev įirst we declare reduced and prev to assign an initialValue of 0 just like Reduce.