Reduce Method In Array Javascript Iterations Matlab