Jump in rank of a student after updating marks | Function to print the name of student who stood first after updation in rank ; Array of students ; Store the name of the student ; Update the marks of the student ; Store the current rank of the student ; Print the name and jump in rank ; Names of the students ; Marks of the students ; Updates that are to be done ; Number of students
function nameRank ( names , marks , updates , n ) { let x = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { x [ i ] = new Array ( 3 ) ; for ( let j = 0 ; j < 3 ; j ++ ) { x [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; i ++ ) { x [ i ] [ 0 ] = names [ i ] x [ i ] [ 1 ] = marks [ i ] + updates [ i ] x [ i ] [ 2 ] = i + 1 } let highest = x [ 0 ] ; for ( let j = 1 ; j < n ; j ++ ) { if ( x [ j ] [ 1 ] >= highest [ 1 ] ) highest = x [ j ] } document . write ( " " , highest [ 0 ] , " " , Math . abs ( highest [ 2 ] - 1 ) , sep = " " ) } let names = [ " " , " " , " " ] ; let marks = [ 80 , 79 , 75 ] ; let updates = [ 0 , 5 , - 9 ] ; let n = marks . length ; nameRank ( names , marks , updates , n )