Skip to content

Instantly share code, notes, and snippets.

@masters3d
Created March 6, 2017 18:42
Show Gist options
  • Save masters3d/00b6f6bec535db3e9da6806a282218d1 to your computer and use it in GitHub Desktop.
Save masters3d/00b6f6bec535db3e9da6806a282218d1 to your computer and use it in GitHub Desktop.
Compares two TypeScript / ES6 maps
function areMapsEqual(left: Map<number, string []>, right: Map<number, string []>): boolean {
if (left.size !== right.size) { return false }
const leftKeys = Array.from(left.keys()).sort()
const rightKeys = Array.from(right.keys()).sort()
if ( leftKeys !== rightKeys ) { return false }
for ( const key of leftKeys ) {
const leftValues = left.get(key) || []
const rightValues = right.get(key) || []
if ( leftValues.sort() !== rightValues.sort()) { return false }
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment