another-guy/problem-solving-ts

View on GitHub

Showing 26 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  pushLeft(value: number): void {
    if (this.unsafeToPush())
      throw new Error(`No space for push`);

    this.topLeftIndex++;
src/cracking-the-coding-interview/3-stacks-and-queues/3-1-single-array-multiple-stacks.ts on lines 117..123

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 68.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  pushRight(value: number): void {    
    if (this.unsafeToPush())
      throw new Error(`No space for push`);

    this.topRightIndex--;
src/cracking-the-coding-interview/3-stacks-and-queues/3-1-single-array-multiple-stacks.ts on lines 100..106

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 68.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      popRight(): number {
        if (this.isRightEmpty)
          throw new Error(`Right stack is empty.`);
        
        const result = this.data[this.topRightIndex];
    src/cracking-the-coding-interview/3-stacks-and-queues/3-1-single-array-multiple-stacks.ts on lines 108..115

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 63.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      popLeft(): number {
        if (this.isLeftEmpty)
          throw new Error(`Left stack is empty.`)
    
        const result = this.data[this.topLeftIndex];
    src/cracking-the-coding-interview/3-stacks-and-queues/3-1-single-array-multiple-stacks.ts on lines 125..132

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 63.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    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

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

      'I': {
        'V': { result: 4, skipNext: true },
        'X': { result: 9, skipNext: true },
        '.': { result: 1, skipNext: false },
      },
    Severity: Major
    Found in src/leet-code/1-easy/13-roman-to-integer.ts and 2 other locations - About 55 mins to fix
    src/leet-code/1-easy/13-roman-to-integer.ts on lines 62..66
    src/leet-code/1-easy/13-roman-to-integer.ts on lines 70..74

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 54.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

      'X': {
        'L': { result: 40, skipNext: true },
        'C': { result: 90, skipNext: true },
        '.': { result: 10, skipNext: false },
      },
    Severity: Major
    Found in src/leet-code/1-easy/13-roman-to-integer.ts and 2 other locations - About 55 mins to fix
    src/leet-code/1-easy/13-roman-to-integer.ts on lines 54..58
    src/leet-code/1-easy/13-roman-to-integer.ts on lines 70..74

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 54.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

      'C': {
        'D': { result: 400, skipNext: true },
        'M': { result: 900, skipNext: true },
        '.': { result: 100, skipNext: false },
      },
    Severity: Major
    Found in src/leet-code/1-easy/13-roman-to-integer.ts and 2 other locations - About 55 mins to fix
    src/leet-code/1-easy/13-roman-to-integer.ts on lines 54..58
    src/leet-code/1-easy/13-roman-to-integer.ts on lines 62..66

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 54.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    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;
      Severity
      Category
      Status
      Source
      Language