Created
March 6, 2017 18:42
-
-
Save masters3d/00b6f6bec535db3e9da6806a282218d1 to your computer and use it in GitHub Desktop.
Compares two TypeScript / ES6 maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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