Skip to content

Instantly share code, notes, and snippets.

@nickbalestra
Created March 24, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickbalestra/2a9d724b66d442f3680410035df4894e to your computer and use it in GitHub Desktop.
Save nickbalestra/2a9d724b66d442f3680410035df4894e to your computer and use it in GitHub Desktop.
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