param recordA param recordB returns import { ResourceRecord } from "../coder/ResourceRecord" ; export function rrComparator ( recordA , recordB ) { if ( recordA . class !== recordB . class ) { return recordA . class - recordB . class ; } if ( recordA . type !== recordB . type ) { return recordA . type - recordB . type ; } const aData = recordA . getRawData ( ) ; const bData = recordB . getRawData ( ) ; const maxLength = Math . max ( aData . length , bData . length ) ; for ( let i = 0 ; i < maxLength ; i ++ ) { if ( i >= aData . length && i < bData . length ) { return - 1 ; } else if ( i >= bData . length && i < aData . length ) { return 1 ; } const aByte = aData . readUInt8 ( i ) ; const bByte = bData . readUInt8 ( i ) ; if ( aByte !== bByte ) { return aByte < bByte ? - 1 : 1 ; } } return 0 ; } export const enum TiebreakingResult { /**
     * The opponent is considered the winner
     */ OPPONENT = - 1 , /**
     * Both try to expose the exact same data
     */ TIE = 0 , /**
     * The host is considered the winner
     */ HOST = 1 } param { ResourceRecord [ ] } host param { ResourceRecord [ ] } opponent returns export function runTiebreaking ( host , opponent ) { const maxLength = Math . max ( host . length , opponent . length ) ; for ( let i = 0 ; i < maxLength ; i ++ ) { if ( i >= host . length && i < opponent . length ) { return TiebreakingResult . OPPONENT ; } else if ( i >= opponent . length && i < host . length ) { return TiebreakingResult . HOST ; } const recordComparison = rrComparator ( host [ i ] , opponent [ i ] ) ; if ( recordComparison !== 0 ) { return recordComparison ; } } return TiebreakingResult . TIE ; }