imam problem sus Bellow and above average :
Submission Info
Status: Wrong Answer
Language: JavaScript
Points: 20
Time: 0.008 s
Memory: 7.78 MB
Date: 17/05/2023 15:54
Test cases
Test case #1: Wrong Answer [0.008 s, 7.78 MB]
Your output (clipped)
avg: 0.00
below: -1
above: 1
Test case #2: Accepted [0.008 s, 7.78 MB]
Your output (clipped)
avg: 0.00
below: -1
above: 1
Test case #3: Wrong Answer [0.008 s, 7.78 MB]
Your output (clipped)
avg: 0.00
below: -1
above: 1
Test case #4: Wrong Answer [0.007 s, 7.78 MB]
Your output (clipped)
avg: 0.00
below: -1
above: 1
Test case #5: Wrong Answer [0.008 s, 7.78 MB]
Your output (clipped)
avg: 0.00
below: -1
above: 1
Submitted code
let input = ‘0,1,-1’;
let print = this.print || console.log;
let gets = this.gets || ((arr, index) => () => arr[index++])(input.split(‘,’), 0);
let numbers = input.split(‘,’).map(Number);
let sum = 0;
for (let i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
let average = sum / numbers.length;
let belowAverage = [];
let aboveAverage = [];
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] < average) {
belowAverage.push(numbers[i]);
} else if (numbers[i] > average) {
aboveAverage.push(numbers[i]);
}
}
print(‘avg: ’ + average.toFixed(2));
print(‘below: ’ + belowAverage.join(’,’));
print(‘above: ’ + aboveAverage.join(’,'));