MediumError HandlingNot started

Validated score average

A results export contains space-separated tokens; damaged scores appear as text. Ignore tokens that are not finite numbers. Print the average of valid scores to two decimals, or NO DATA when none are valid.

Input

One line containing 1 to 100 space-separated tokens.

Output

The valid-score average with two decimal places, or NO DATA.

Example 1

Input

10 bad 20 15x 30

Output

20.00

Only 10, 20 and 30 pass strict numeric validation.

Constraints

  • Valid scores are between -10000 and 10000
  • Invalid tokens contain no whitespace

Hints

Hint 1 of 3

Number(token) performs a complete conversion unlike parseFloat.

Hint 2 of 3

Number.isFinite rejects NaN and infinities.

Hint 3 of 3

Check values.length before reducing and dividing.

Solution

Show a reference solution and explanation
 JavaScript · reference solution
const tokens = readline().split(' ');
const values = [];
for (const token of tokens) {
  const value = Number(token);
  if (token !== '' && Number.isFinite(value)) values.push(value);
}
if (values.length === 0) console.log('NO DATA');
else console.log((values.reduce((sum, value) => sum + value, 0) / values.length).toFixed(2));

Why it works

Strict conversion rejects partial values such as 15x, which parseFloat would incorrectly accept as 15. The empty-array branch prevents invalid reduction or division and gives the requested explicit result.

Lesson for this exercise: Error Handling in JavaScript

Your program
const tokens = readline().split(' ');
const values = [];
// validate and collect numeric tokens
// print the average or NO DATA

Tests: 4 cases including the examples. Passing every test marks the exercise solved in this browser.

How this page was checked. Every program on it was run with Node.js 22 at build time; runs in your browser in an isolated Web Worker by the publishing checks, and the output shown is what it printed. The Run buttons execute the same code on your device; nothing you type is sent anywhere.