Vertical and Horizontal retrieval ( MRT ) on Tapes | Javascript program to print Horizontal filling ; It is used for checking whether tape is full or not ; It is used for calculating total retrieval time ; It is used for calculating mean retrieval time ; vector is used because n number of records can insert in one tape with size constraint ; Null vector obtained to use fresh vector ' v ' ; initialize variables to 0 for each iteration ; sum is used for checking whether i 'th tape is full or not ; check sum less than size of tape ; increment in j for next record ; calculating total retrieval time ; MRT formula ; calculating mean retrieval time using formula ; v . size ( ) is function of vector is used to get size of vector ; Driver Code ; store the size of records [ ] ; store the size of tapes [ ] ; sorting of an array is required to attain greedy approach of algorithm
function horizontalFill ( records , tape , nt ) { let sum = 0 ; let Retrieval_Time = 0 ; let Mrt ; let current = 0 ; let v = [ ] ; for ( let i = 0 ; i < nt ; i ++ ) { v = [ ] ; Retrieval_Time = 0 ; sum = 0 ; document . write ( " " + ( i + 1 ) + " " ) ; sum += records [ current ] ; while ( sum <= tape [ i ] ) { document . write ( records [ current ] + " " ) ; v . push ( records [ current ] ) ; current ++ ; sum += records [ current ] ; } document . write ( " " ) ; for ( let j = 0 ; j < v . length ; j ++ ) { Retrieval_Time += v [ j ] * ( v . length - j ) ; } Mrt = Retrieval_Time / v . length ; if ( i == 0 ) { document . write ( " " + Mrt . toFixed ( 4 ) + " " ) ; } else { document . write ( " " + Mrt + " " ) ; } } } let records = [ 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 ] ; let tape = [ 25 , 80 , 160 ] ; let n = records . length ; let m = tape . length ; records . sort ( function ( a , b ) { return a - b } ) ; horizontalFill ( records , tape , m ) ;