lulalachen/algorithm

View on GitHub

Showing 80 of 272 total issues

Function removeInvalidParentheses has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

var removeInvalidParentheses = function(rawString) {
  const validExpression = new Set()

  let leftToRemoveCount = 0
  let rightToRemoveCount = 0
Severity: Minor
Found in src/leetcode/301-remove-invalid-parentheses.js - About 5 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 threeSum has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

const threeSum = nums => {
  const result = []
  nums.sort((a, b) => a > b)
  for (let i = 0; i < nums.length; i++) {
  let lowIndex = i + 1
Severity: Minor
Found in src/leetcode/15-3sum.js - About 5 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 isNumber has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

var isNumber = function(s) {
  const trimmed = s.trim()
  let flag = 0
  let state = 0
  
Severity: Minor
Found in src/leetcode/65-valid-number.js - About 4 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 accountsMerge has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

const accountsMerge = accounts => {
  const ans = []
  const emailGraph = {}
  const emailToName = {}
  
Severity: Minor
Found in src/leetcode/721-accounts-merge.js - About 3 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 isBipartite has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

var isBipartite = function (graph) {
  const n = graph.length
  const colors = Array(n).fill(-1) // -1 as uncoloerd
  
  for (let start = 0; start < n; start++) {
Severity: Minor
Found in src/leetcode/785-is-graph-bipartite.js - About 3 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 removeInvalidParentheses has 75 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var removeInvalidParentheses = function(rawString) {
  const validExpression = new Set()

  let leftToRemoveCount = 0
  let rightToRemoveCount = 0
Severity: Major
Found in src/leetcode/301-remove-invalid-parentheses.js - About 3 hrs to fix

    Function minWindow has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    var minWindow = function(s, t) {
      if (s.length === 0 || t.length === 0) {
      return ""
      }
      const dictT = new Map()
    Severity: Minor
    Found in src/leetcode/76-minimum-window-substring.js - 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 wordBreak has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    var wordBreak = function(s, wordDict) {
      let map = new Map()
      
      const dfs = (string, wordDict, start) => {
      if (map.has(start)) return map.get(start) // use cache
    Severity: Minor
    Found in src/leetcode/140-word-break-ii.js - 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 alienOrder has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    const alienOrder = words => {
      const graph = new Map()
      
      for (const word of words) {
      for (const char of word.split('')) {
    Severity: Minor
    Found in src/leetcode/269-alien-dictionary.js - 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 addOperators has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    var addOperators = function (num, target) {
      const ans = []
      const helper = (index, path, value, prev) => {
      if (index === num.length && value === target) {
        // console.log('ret', ans, path)
    Severity: Minor
    Found in src/leetcode/282-expression-add-operators.js - 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 recursive has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      const recursive = (string, index, leftCount, rightCount, leftRem, rightRem, expression) => {
      // console.log(validExpression)
      // console.log(index, leftCount, rightCount, leftRem, rightRem, expression)
      if (index === string.length) {
        // Base case: if index reaches the end of the string
    Severity: Major
    Found in src/leetcode/301-remove-invalid-parentheses.js - About 2 hrs to fix

      Function searchRange has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      var searchRange = function(nums, target) {
        let i = 0
        let j = -1
      
        while (i < nums.length) {

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

      var maxSumOfThreeSubarrays = function(nums, K) {
        // W is an array of sums of windows
        const W = Array(nums.length - K + 1).fill(0)
        let sum = 0;
        for (let i = 0; i < nums.length; i++) {
      Severity: Minor
      Found in src/leetcode/689-maximum-sum-of-3-non-overlapping-subarrays.js - 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 wordBreak2 has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      const wordBreak2 = (s, wordDict) => {
        const dictSet = new Set(wordDict)
      
        const queue = []
        const visited = Array.from(Array(s.length)).map(() => false)
      Severity: Minor
      Found in src/leetcode/139-word-break.js - 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 minDominoRotations has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      var minDominoRotations = function (A, B) {
        const positionMap = new Map()
        const A_ROW = 'A_ROW'
        const B_ROW = 'B_ROW'
        const BOTH = 'BOTH'
      Severity: Minor
      Found in src/leetcode/1007-minimum-domino-rotations-for-equal-row.js - About 1 hr to fix

        Function alienOrder has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const alienOrder = words => {
          const graph = new Map()
          
          for (const word of words) {
          for (const char of word.split('')) {
        Severity: Minor
        Found in src/leetcode/269-alien-dictionary.js - About 1 hr to fix

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

          const longestPalindromeDP = str => {
            const dp = new Map()
            if (!str) return ''
            let longestStart = 0
            let longestLength = 1
          Severity: Minor
          Found in src/leetcode/5-longest-palindromic-substring.js - 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 search has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

          WordDictionary.prototype.search = function (word) {
            const match = (words, k, node) => {
            if (k === words.length) {
              return node.word !== ""
            }
          Severity: Minor
          Found in src/leetcode/211-add-and-search-word-data-structure-design.js - 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 minWindow has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          var minWindow = function(s, t) {
            if (s.length === 0 || t.length === 0) {
            return ""
            }
            const dictT = new Map()
          Severity: Minor
          Found in src/leetcode/76-minimum-window-substring.js - About 1 hr to fix

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

            var maxSumOfThreeSubarrays = function(nums, K) {
              // W is an array of sums of windows
              const W = Array(nums.length - K + 1).fill(0)
              let sum = 0;
              for (let i = 0; i < nums.length; i++) {
            Severity: Minor
            Found in src/leetcode/689-maximum-sum-of-3-non-overlapping-subarrays.js - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language