Scriptdrill

Level 4: Data shaping Exercise 32 of 45 Pro

Running totals

A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.

The task

Return a new array where each position holds the sum of all numbers up to and including that position. Do not change `nums`.

What this exercise teaches

One variable carries the sum from one position to the next, so each step costs one addition. map builds the new array and leaves nums as it was.

A hint if you get stuck

Keep a running total in a variable and `map` each number to the total after adding it.

This exercise is part of Pro

Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Data shaping