another-guy/problem-solving-ts

View on GitHub
src/cracking-the-coding-interview/8-recursion-and-dynamic-programming/8-2-robot-in-a-grid.ts

Summary

Maintainability
C
7 hrs
Test Coverage

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 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[] = [];

    Avoid too many return statements within this function.
    Open

      return null;

      There are no issues that match your filters.

      Category
      Status