cognitive-complexity-ts
Version:
This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf). It produces a JSON summary and a GUI for exploring the complexity of your codebase.
41 lines • 979 B
JavaScript
export function arrayToMap(keys, mapper) {
const m = new Map();
keys.forEach((key) => {
m.set(key, mapper(key));
});
return m;
}
export function computeOnce(func) {
let result;
let notComputed = true;
return () => {
if (notComputed) {
result = func();
notComputed = false;
}
return result;
};
}
export function iterMap(iter, mapper) {
const result = [];
for (const val of iter) {
result.push(mapper(val));
}
return result;
}
export function removeAll(arr, predicate) {
const badIndexes = [];
const badElems = [];
for (let i = 0; i < arr.length; i++) {
if (predicate(arr[i])) {
badIndexes.push(i);
badElems.push(arr[i]);
}
}
for (let i = badElems.length - 1; i >= 0; i--) {
const badIndex = badIndexes[i];
arr.splice(badIndex, 1);
}
return badElems;
}
//# sourceMappingURL=util.js.map