Edit: I missed the multi-dimensional aspect of this question, so I'm leaving this here in case it helps people compare one-dimensional arrays
It's an old question, but I was having issues with the speed of using .sort()
or sortBy()
, so I used this instead:
function arraysContainSameStrings(array1: string[], array2: string[]): boolean {
return (
array1.length === array2.length &&
array1.every((str) => array2.includes(str)) &&
array2.every((str) => array1.includes(str))
)
}
It was intended to fail fast, and for my purposes works fine.