sularome/JavaScript-Algorithms

View on GitHub

Showing 28 of 30 total issues

Function addFixup has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    private addFixup(node: RedBlackTreeNode<T>) {
        while (node.parent.isRed()) {
            if (node.parent.isLeftChild()) {
                let parentSibling = node.parent.parent.right;
                if (parentSibling.isRed()) {
Severity: Minor
Found in ts/BinaryTree/RedBlackTree.ts - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function insert has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    insert(word: string, value: T) {
        let currentNode: RadixTreeNode<T> = this.root;
        let cumulatedWord: string = "";
        while (true) {
            const sufix: string = word.substr(cumulatedWord.length);
Severity: Minor
Found in ts/RadixTree.ts - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function addFixup has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private addFixup(node: RedBlackTreeNode<T>) {
        while (node.parent.isRed()) {
            if (node.parent.isLeftChild()) {
                let parentSibling = node.parent.parent.right;
                if (parentSibling.isRed()) {
Severity: Minor
Found in ts/BinaryTree/RedBlackTree.ts - About 1 hr to fix

    Function FindMaximumSubarray has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function FindMaximumSubarray (array: number[], left: number = 0, right: number = array.length): number[] {
        if (left === right) {
            return [left, right, left > array.length ? -Infinity : array[left]];
        } else {
            const middle = Math.floor((left + right) / 2);
    Severity: Minor
    Found in ts/FindMaximumSubarray.ts - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function extendedEuclidesAlgorithm has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function extendedEuclidesAlgorithm(a: number, b: number): IExtendedEuclidesAlgorithmResult {
        if (!Number.isInteger(a) || !Number.isInteger(b)) {
            throw new Error("Euclide's extended algorithm works only for positive integers");
        }
        if (a === 0 && b === 0) {
    Severity: Minor
    Found in ts/functions/extendedEuclidesAlgorithm.ts - About 1 hr to fix

      Function add has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public add(value: T): void {
              let currentNode: IBinaryTreeNode<T> = this.root;
              let futureParent: IBinaryTreeNode<T> = null;
              const newNode: IBinaryTreeNode<T> = new BinaryTreeNode(value, null);
              while (currentNode !== null) {
      Severity: Minor
      Found in ts/BinaryTree/BinaryTree.ts - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function insert has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          insert(word: string, value: T) {
              let currentNode: RadixTreeNode<T> = this.root;
              let cumulatedWord: string = "";
              while (true) {
                  const sufix: string = word.substr(cumulatedWord.length);
      Severity: Minor
      Found in ts/RadixTree.ts - About 1 hr to fix

        Function splice has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public splice(startIndex: number, deleteCount: number): void {
                if (isNaN(deleteCount) || deleteCount < 1) {
                    return;
                }
                if (startIndex < 0) {
        Severity: Minor
        Found in ts/BitArray.ts - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function extendedEuclidesAlgorithm has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        export function extendedEuclidesAlgorithm(a: number, b: number): IExtendedEuclidesAlgorithmResult {
            if (!Number.isInteger(a) || !Number.isInteger(b)) {
                throw new Error("Euclide's extended algorithm works only for positive integers");
            }
            if (a === 0 && b === 0) {
        Severity: Minor
        Found in ts/functions/extendedEuclidesAlgorithm.ts - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function merge has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        function merge(array: number[], reverse: boolean, startIndex: number, middleIndex: number, endIndex: number) {
            const left: number[] = array.slice(startIndex, middleIndex);
            const right: number[] = array.slice(middleIndex, endIndex);
            left.push(reverse ? -Infinity : Infinity);
            right.push(reverse ? -Infinity : Infinity);
        Severity: Minor
        Found in ts/Sort/mergeSort.ts - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function greatestCommonDivisor has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        export function greatestCommonDivisor(a: number, b: number): number {
            if (!Number.isInteger(a) || !Number.isInteger(b)) {
                return NaN;
            }
            if (a === 0 && b === 0) {
        Severity: Minor
        Found in ts/functions/greatestCommonDivisor.ts - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function bubbleSort has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        function bubbleSort<T>(array: T[], comparator: (a: T, b: T) => boolean = (a, b) => a > b) {
            if (!Array.isArray(array) || array.length < 2) {
                return array;
            }
            let isNotSorted: boolean = true;
        Severity: Minor
        Found in ts/Sort/bubbleSort.ts - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function merge has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        function merge(array: number[], reverse: boolean, startIndex: number, middleIndex: number, endIndex: number) {
        Severity: Minor
        Found in ts/Sort/mergeSort.ts - About 35 mins to fix

          Function add has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public add(value: T): void {
                  let parent: RedBlackTreeNode<T> = this.sentinel;
                  let currentLoopNode: RedBlackTreeNode<T> = this.root;
                  const newNode: RedBlackTreeNode<T> = new RedBlackTreeNode(value, RedBlackTreeNode.sentinel, false);
                  while (currentLoopNode.isNotSentinel()) {
          Severity: Minor
          Found in ts/BinaryTree/RedBlackTree.ts - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function mergeSort has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function mergeSort (array: number[], reverse = false, startIndex?: number, endIndex?: number) {
              if (!Array.isArray(array)) {
                  return array;
              }
              startIndex = startIndex === void 0 ? 0 : startIndex;
          Severity: Minor
          Found in ts/Sort/mergeSort.ts - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function quickSort has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function quickSort<T>(array: T[], comparator: SortingComparator<T> = Utils.gt, leftIndex: number = 0, rightIndex: number = -1): T[] {
              if (!Array.isArray(array) || array.length < 2) {
                  return array;
              }
          
          
          Severity: Minor
          Found in ts/Sort/quickSort.ts - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function gnomeSort has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function gnomeSort<T>(array: T[], comparator: (a: T, b: T) => boolean = (a, b) => a > b) {
              if (!Array.isArray(array) || array.length < 2) {
                  return array;
              }
          
          
          Severity: Minor
          Found in ts/Sort/gnomeSort.ts - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function insertionSort has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          function insertionSort<T> (array: T[], comparator: SortingComparator<T> = Utils.gt, startIndex: number = 0, endIndex: number = -1) {
              if (!Array.isArray(array)) {
                  return array;
              }
          
          
          Severity: Minor
          Found in ts/Sort/insertionSort.ts - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid too many return statements within this function.
          Open

                  return  greatestCommonDivisorInternal(a, b);
          Severity: Major
          Found in ts/functions/greatestCommonDivisor.ts - About 30 mins to fix

            Function search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public search(value: T): RedBlackTreeNode<T> {
                    let currentNode: RedBlackTreeNode<T> = this.root;
                    while (currentNode !== this.sentinel && currentNode.value !== value) {
                        if (this.comparator(currentNode.value, value)) {
                            currentNode = currentNode.left;
            Severity: Minor
            Found in ts/BinaryTree/RedBlackTree.ts - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Severity
            Category
            Status
            Source
            Language