Function to search the most recent location of element N If not present in the array it will return - 1
function search ( a , k , x ) { var j ; for ( j = k - 1 ; j > - 1 ; j -- ) { if ( a [ j ] == x ) return j ; } return - 1 ; }