Store the index of current element and its just smaller element in array w [ ]
var currElementPos = pos . get ( a [ curr ] ) ; var prevElementPos = pos . get ( a [ curr - 1 ] ) ; if ( currElementPos > prevElementPos ) continue ;