export function scrambledEqual < T > ( array1 , array2 ) { if ( ! array1 ) { throw new Error ( 'undefined first array' ) ; } if ( ! array2 ) { throw new Error ( 'undefined second array' ) ; } const sortedArray1 = sort ( array1 ) ; const sortedArray2 = sort ( array2 ) ; return sequenceEqual ( sortedArray1 , sortedArray2 ) ; function sort ( array ) { return array . slice ( ) . sort ( ) ; } } export function sequenceEqual < T > ( array1 , array2 ) { if ( ! array1 ) { throw new Error ( 'undefined first array' ) ; } if ( ! array2 ) { throw new Error ( 'undefined second array' ) ; } if ( array1 . length !== array2 . length ) { return false ; } return array1 . every ( ( val , index ) => val === array2 [ index ] ) ; }