Skip to content

Array sum

TypeScript for + types

Same task in: CJavaScript

Flowchart (ISO 5807)

StartInput arrs = 0i = 0, |arr| − 1, 1s = s + arr[i]Return sEndFigure 1 — sum

Source code

TypeScript
function sum(arr: number[]): number {
    let s = 0;
    for (let i = 0; i < arr.length; i++) {
        s += arr[i];
    }
    return s;
}

The editor opens with this code — change it and the chart redraws.

Language
TypeScript
Constructs
for + types
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples