cognitive-complexity-ts
Version:
This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf).
40 lines • 953 B
JavaScript
export class EqMap {
constructor(eq) {
this.eq = eq;
this.map = new Map();
}
findRealKey(givenKey) {
for (const existingKey of this.map.keys()) {
if (this.eq(givenKey, existingKey)) {
return existingKey;
}
}
return undefined;
}
get(key) {
if (this.map.has(key)) {
return this.map.get(key);
}
const realKey = this.findRealKey(key);
if (realKey === undefined) {
return undefined;
}
return this.map.get(realKey);
}
has(key) {
if (this.map.has(key)) {
return true;
}
return this.findRealKey(key) !== undefined;
}
set(key, val) {
this.map.set(key, val);
}
values() {
return this.map.values();
}
[Symbol.iterator]() {
return this.map[Symbol.iterator]();
}
}
//# sourceMappingURL=EqMap.js.map