Students with maximum average score of three subjects | Function to find the list of students having maximum average score Driver code ; Variables to store average score of a student and maximum average score ; List to store names of students having maximum average score ; Traversing the file data ; finding average score of a student ; Clear the list and add name of student having current maximum average score in the list ; Printing the maximum average score and names of students having this maximum average score as per the order in the file . ; Driver code ; Number of elements in string array
function getStudentsList ( file , n ) { let avgScore ; let maxAvgScore = Number . MIN_SAFE_INTEGER ; let names = [ ] ; for ( let i = 0 ; i < n ; i += 4 ) { avgScore = Math . floor ( ( Number ( file [ i + 1 ] ) + Number ( file [ i + 2 ] ) + Number ( file [ i + 3 ] ) ) / 3 ) ; if ( avgScore > maxAvgScore ) { maxAvgScore = avgScore ; names = [ ] ; names . push ( file [ i ] ) ; } else if ( avgScore == maxAvgScore ) names . push ( file [ i ] ) ; } for ( let i = 0 ; i < names . length ; i ++ ) { document . write ( names [ i ] + " " ) ; } document . write ( maxAvgScore ) ; } let file = [ " " , " " , " " , " " , " " , " " , " " , " " ] ; let n = file . length ; getStudentsList ( file , n ) ;