export function removePairs < T > ( input , excludeWhen ) { const WIDTH = 2 ; let currentPos = 0 ; const res = [ ] ; while ( currentPos + 1 < input . length ) { const firstVal = input [ currentPos ] ; const secondVal = input [ currentPos + 1 ] ; if ( excludeWhen ( firstVal , secondVal ) ) { currentPos += WIDTH ; continue ; } else { res . push ( firstVal ) ; currentPos += 1 ; } } if ( currentPos + 1 === input . length ) { res . push ( input [ currentPos ] ) ; } return res ; }