Question: function getAverage ( nums ) { const sum = nums.reduce ( ( acc , val ) = > acc + val, 0 ) ; return
function getAveragenums
const sum nums.reduceacc val acc val, ;
return sum nums.length;
function highestAveragenumsList
let highestAverage Infinity;
let highestIndex ;
for let i ; i numsList.length; i
const subArraySum numsListireducesum num sum num, ;
const subArrayAverage subArraySum numsListilength;
if subArrayAverage highestAverage
highestAverage subArrayAverage;
highestIndex i;
return highestIndex;
TESTS
DO NOT MODIFY ANYTHING BELOW THIS LINE
const arrayA ;
const arrayB ;
const arrayC ;
const arrayD ;
let score ;
if getAveragearrayA score;
if getAveragearrayB score;
if getAveragearrayC score;
if getAveragearrayD score;
if highestAveragearrayA arrayB, arrayC, arrayD score;
if highestAveragearrayA arrayB score;
if highestAveragearrayA arrayD score;
console.logYou have scored score points.";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
