Last updated 4 years ago
Was this helpful?
iterate 0 to n ( i )
(inside process-1) Start the first index with i and increment the index by n until the index equals values.length.
while iterate process-1-1, sum each index value
when finish process 1-1 add sum value to the result stack
return result;
const beggars = (values, n) => { const result = []; let sum = 0; for (let i = 0; i < n; i += 1) { sum = 0; for (let j = i; j < values.length; j += n) { sum += values[j]; } result.push(sum); } return result; };