Skip to content

Instantly share code, notes, and snippets.

@srir
Last active August 29, 2015 14:27
Show Gist options
  • Save srir/66ec4751ad88417c5c66 to your computer and use it in GitHub Desktop.
Save srir/66ec4751ad88417c5c66 to your computer and use it in GitHub Desktop.
export function dedupeLists<T>(listOfLists: T[][], hash: (obj: T) => string): T[][] {
var all: { [hash: string]: boolean; } = {};
var resultList: T[][] = [];
listOfLists.forEach((list) => {
var results: T[] = [];
list.forEach((obj) => {
var key = hash(obj);
if (!all.hasOwnProperty(key)) {
all[key] = true;
results.push(obj);
}
});
resultList.push(results);
});
return resultList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment