another-guy/problem-solving-ts

View on GitHub

Showing 19 of 26 total issues

Function findPath has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

export function findPath(grid: Grid): Move[] | null {
  if (!grid || !grid.length) return null;

  const hintTable: string[][] = [];
  const path: Move[] = [];

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 findPathRecursively has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

export function findPathRecursively(grid: Grid, rowIndex?: number, columnIndex?: number): Move[] | null {
  if (!grid || !grid.length) return null;

  rowIndex = rowIndex != null ? rowIndex : grid.length - 1;
  columnIndex = columnIndex != null ? columnIndex : grid[0].length - 1;

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 dijkstraShortestPath has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

export function dijkstraShortestPath(
  graph: IUndirectedGraph,
  sourceNode: string,
  destinationNode: string,
): IPath {
Severity: Minor
Found in src/practice/1-2-dijkstra-shortest-path.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 findPath has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function findPath(grid: Grid): Move[] | null {
  if (!grid || !grid.length) return null;

  const hintTable: string[][] = [];
  const path: Move[] = [];

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

    export function trimLongMessage(message: string, maxLength: number): string {
      if (!message) return '';
    
      const words = message.split(' ');
      let result = '';
    Severity: Minor
    Found in src/codility/trim-long-message.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 tripleStep has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    export function tripleStep(stepsCount: number): number {
      if (stepsCount <= 0) throw new Error(`${stepsCount} of steps is not a real stair!`);
      else if (stepsCount === 1) return 1;
      else if (stepsCount === 2) return 2;
      else if (stepsCount === 3) return 4;

    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 graphsEqual has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export function graphsEqual(graph1: IUndirectedGraph, graph2: IUndirectedGraph): boolean {
      if (!graph1 || !graph2) throw new Error(`Compared graphs can not be null/undefined`);
      
      if (graph1.nodes.length !== graph2.nodes.length) return false;
      const someNodeMissing = graph1.nodes.some(node => graph2.nodes.indexOf(node) < 0);
    Severity: Minor
    Found in src/practice/0-undirected-graph.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 magicIndex has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    export function magicIndex(
      array: number[],
      lowIndex: number = 0,
      highIndex = array.length - 1,
    ): number | null {

    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 twoSum has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    var twoSum = function(nums: number[], target: number): number[] {
      const valuesAndIndices = nums.reduce((subResult, value, index) => {
        const indices = subResult[value];
        indices ? indices.push(index) : subResult[value] = [index];
        return subResult;
    Severity: Minor
    Found in src/leet-code/1-easy/1-two-sum.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 isTopSort has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    export function isTopSort(
      orderedNodes: string[],
      graph: IDirectedGraph,
    ): boolean {
      if (graph.nodes.length !== (orderedNodes || []).length) return false;
    Severity: Minor
    Found in src/practice/1-1-top-sort.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 numberOfWaysToJumpToNthStep has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    export const numberOfWaysToJumpToNthStep = (n) => {
      if (n < 0) throw new Error(`Cmon, you cant jump onto a negative step; but I'd be able to provide a math to that problem if necessary!`);
    
      if (memo.has(n)) return memo.get(n);
    
    
    Severity: Minor
    Found in src/hired/1-2-number-of-ways-to-jump-to-n-th-step.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 romanToInt has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    export const romanToInt = function(roman: string): number {
      if (!roman || !roman.length) throw new Error(`${roman} is not a Roman number.`);
    
      const queue = roman.toUpperCase().split('');
      let result = 0;
    Severity: Minor
    Found in src/leet-code/1-easy/13-roman-to-integer.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 null;

      Avoid too many return statements within this function.
      Open

        else return magicIndex(array, lowIndex, index - 1);

        Avoid too many return statements within this function.
        Open

          return true;
        Severity: Major
        Found in src/practice/0-undirected-graph.ts - About 30 mins to fix

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

          export function pathExists(graph: Graph, source: string, destination: string): boolean {
            const visited = new Set<string>();
            const toVisit = [ source ];
            while (toVisit.length) {
              const currentNode = toVisit.shift();

          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 splitIntoGroups has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function splitIntoGroups(bitSequence: string): { g: string, c: number }[] {
            const groups: { g: string, c: number }[] = [];
            let index = 0;
            let group = bitSequence[index];
            let groupLen = 1;
          Severity: Minor
          Found in src/coding-game/1-easy/chuck-norris.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

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

          export function pathExists(source: string, destination: string, graph: IDirectedGraph): boolean {
            const toVisit = [source];
            const visited = new Set<string | undefined>([]);
          
            while (toVisit.length) {
          Severity: Minor
          Found in src/practice/1-1-top-sort.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

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

          var twoSumBruteForce = function(nums: number[], target: number): number[] {
            for (let left = 0; left < nums.length - 1; left++)
              for (let right = left + 1; right < nums.length; right++)
                if (nums[left] + nums[right] === target)
                  return [left, right];
          Severity: Minor
          Found in src/leet-code/1-easy/1-two-sum.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