Languages
[Edit]
EN

TypeScript - average value calculation

0 points
Created by:
a_horse
538

In this article, we would like to show you how to calculate the average value in TypeScript.

Runnable example:

const calculateAverage = (array: number[]): number => {
    let sum = 0;
    for (let i = 0; i < array.length; ++i) {
        sum += array[i];
    }
    return sum / array.length;
};


// Usage example:

const numbers: number[] = [10, 20, 30];
const average: number = calculateAverage(numbers);

console.log(average);

Output:

20

See also

  1. JavaScript - average value calculation

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join