An implementation of Map<TKey, TValue>
and Set<TValue>
that can use custom equals
and getHashCode
functions.
A case-insensitve set, using EqualityComparer<T>
and getHashCode
const names = ["zebra", "antelope", "ardvaark", "tortoise", "turtle", "dog", "frog"]
const comparer: EqualityComparer<string> = {
equals: (a, b) => a.toLowerCase() === b.toLowerCase(),
getHashCode: (x) => getHashCode(x.toLowerCase())
}
const set = createComparerSet(comparer)
names.forEach(n => set.add(n))
expect(set.has("DOg")).toBeTruthy()
Created using the wonderful https://github.com/alexjoverm/typescript-library-starter.