export function find < T > ( o , predicate ) { if ( o == null ) { throw new TypeError ( '"o" is null or not defined' ) ; } const len = o . length >>> 0 ; if ( typeof predicate !== "function" ) { throw new TypeError ( "predicate must be a function" ) ; } const thisArg = arguments [ 1 ] ; let k = 0 ; while ( k < len ) { const kValue = o [ k ] ; if ( predicate . call ( thisArg , kValue , k , o ) ) { return kValue ; } k ++ ; } return undefined ; } export interface IDifferences2 < T > { update : T [ ] ; exit : T [ ] ; enter : T [ ] ; } export function compare < T > ( before , after ) { const retVal = { update : [ ] , exit : [ ] , enter : [ ... after ] } ; for ( const row of before ) { const otherIdx = retVal . enter . indexOf ( row ) ; if ( otherIdx >= 0 ) { retVal . update . push ( row ) ; retVal . enter . splice ( otherIdx , 1 ) ; } else { retVal . exit . push ( row ) ; } } return retVal ; } export interface IDifferences2 < T > { enter : T [ ] ; update : T [ ] ; exit : T [ ] ; } export function compare2 < T > ( before , after , idFunc , updateFunc = ( before , after ) => after ) { const retVal = { update : [ ] , exit : [ ] , enter : [ ] } ; if ( before === after ) { retVal . update = before as T [ ] ; return retVal ; } const unknownMap = { } ; after . forEach ( item => { unknownMap [ idFunc ( item ) ] = item ; } ) ; for ( const row of before ) { const id = idFunc ( row ) ; const item = unknownMap [ id ] ; if ( item !== undefined ) { delete unknownMap [ id ] ; retVal . update . push ( updateFunc ( row , item ) ) ; } else { retVal . exit . push ( row ) ; } } for ( const key in unknownMap ) { retVal . enter . push ( unknownMap [ key ] ) ; } return retVal ; }