chore: printRunningSum

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-25 03:20:07 +01:00
parent 4d1ba98592
commit aa64f04d69
2 changed files with 26 additions and 16 deletions

View File

@@ -22,7 +22,16 @@ export const compute = (
.filter((part) => !isNaN(Number(part)) && part.trim() !== '')
.map(Number);
}
return numbers
.reduce((previousValue, currentValue) => previousValue + currentValue, 0)
.toString();
if (printRunningSum) {
let result: string = '';
let sum: number = 0;
for (const i of numbers) {
sum = sum + i;
result = result + sum + '\n';
}
return result;
} else
return numbers
.reduce((previousValue, currentValue) => previousValue + currentValue, 0)
.toString();
};