import { Check } from './checks' ; type CheckKey = keyof Check ; function checksAreEqual ( check1 , check2 ) { let areEqual = true ; for ( const key in check1 ) { if ( check1 [ key as CheckKey ] !== check2 [ key as CheckKey ] ) { areEqual = false ; break ; } } return areEqual ; } function removeDuplicates ( targetArray , comparisonArray ) { return targetArray . filter ( targetCheck => { return ! comparisonArray . some ( check => { return targetCheck . url === check . url ; } ) ; } ) ; } export function getDeltas ( currentChecks , expectedChecks ) { const deletions = removeDuplicates ( currentChecks , expectedChecks ) ; const additions = removeDuplicates ( expectedChecks , currentChecks ) ; const updates = expectedChecks . map ( expectedCheck => { const matchingCheck = currentChecks . find ( currentCheck => currentCheck . url === expectedCheck . url ) ; const tokenedMatchingCheck = matchingCheck ? { ... expectedCheck , token : matchingCheck . token , } : undefined ; return matchingCheck && tokenedMatchingCheck && ! checksAreEqual ( tokenedMatchingCheck , matchingCheck ) ? tokenedMatchingCheck : undefined ; } ) . filter ( Boolean ) as Check [ ] ; return { deletions , updates , additions , } ; }