TypeScript bootcamp · Lab 47

Average

easyArrays10 minLesson: Arrays

Read the question, write TypeScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Average of space-separated numbers.

Examples

Example 1
Input
2 4 6
Output
4
Hint
  1. sum/length
Show correct code

Peek only after you have tried. You can still Check your own version.

const nums: number[] = readLine().trim().split(/\s+/).map(Number);
console.log(nums.reduce((a, b) => a + b, 0) / nums.length);
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.