function findByPredicate < T > ( arr , filter ) { for ( const [ index , value ] of arr . entries ( ) ) { if ( filter ( value ) ) { return { index , value } ; } } return undefined ; } export function findAndPushToEnd < T > ( arr , filter ) { const result = findByPredicate ( arr , filter ) ; if ( result == null ) { return undefined ; } const { index , value } = result ; arr . splice ( index , 1 ) ; arr . push ( value ) ; return value ; }