cognitive-complexity-ts
Version:
This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf).
31 lines • 779 B
JavaScript
export class SortedMap {
constructor(map = new Map()) {
this.map = map;
this.sortedKeys = [...map.keys()];
}
clone() {
const newSortedMap = Object.create(SortedMap.prototype);
newSortedMap.map = new Map(this.map);
newSortedMap.sortedKeys = [...this.sortedKeys];
newSortedMap.constructor = SortedMap;
return newSortedMap;
}
get(key) {
return this.map.get(key);
}
get size() {
return this.sortedKeys.length;
}
sort(sorter) {
this.sortedKeys.sort(sorter);
}
keys() {
return this.sortedKeys;
}
*values() {
for (const key of this.sortedKeys) {
yield this.map.get(key);
}
}
}
//# sourceMappingURL=SortedMap.js.map