Skip to content

Instantly share code, notes, and snippets.

@NAZIMUDHEEN267
Created March 29, 2023 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NAZIMUDHEEN267/c61dbaf139587a2c7fc4d242a7a9a74f to your computer and use it in GitHub Desktop.
Save NAZIMUDHEEN267/c61dbaf139587a2c7fc4d242a7a9a74f to your computer and use it in GitHub Desktop.
Get all the numbers sum that passed on the "runningSum" function
function runningSum(nums: number[]): number[] {
let sum = [nums[0]];
for(let i=1; i<nums.length; i++) {
sum[i] = sum[i-1] + nums[i];
}
return sum;
}
runningSum([1,2,3,4,5,6,7,8,9,10) // return [1, 3, 6, 10, 15, 21, 28, 36, 45, 55];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment