Created
March 24, 2018 15:29
-
-
Save nickbalestra/2a9d724b66d442f3680410035df4894e to your computer and use it in GitHub Desktop.
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 compat(arr) { | |
const compatMap = new Map(); | |
arr.forEach(tuple => { | |
const tupleToCompat = compatMap.get(tuple[0]); | |
if (tupleToCompat) { | |
compatMap.set(tuple[1], tupleToCompat.concat(tuple[1])); | |
compatMap.delete(tuple[0]); | |
} else { | |
compatMap.set(tuple[1], tuple); | |
} | |
}); | |
return [...compatMap.values()]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment