nodef/extra-number

View on GitHub
src/index.ts

Summary

Maintainability
D
2 days
Test Coverage
A
96%

File index.ts has 328 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// #region METHODS
// ===============

// #region ABOUT
// -------------
Severity: Minor
Found in src/index.ts - About 3 hrs to fix

    Function maxPrimeFactor has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    export function maxPrimeFactor(x: number): number {
      var x = Math.abs(x), a = 0;
      // 1. GPF of 2, 3 is the number itself.
      if (x<=1) return 0;
      if (x<=3) return x;
    Severity: Minor
    Found in src/index.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 minPrimeFactor has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export function minPrimeFactor(x: number): number {
      var x = Math.abs(x);
      // 1. LPF of 2, 3 is the number itself.
      if (x<=1) return 0;
      if (x<=3) return x;
    Severity: Minor
    Found in src/index.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 remap has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Invalid

    export function remap(x: number, r: number, R: number, t: number, T: number): number {
    Severity: Minor
    Found in src/index.ts - About 35 mins to fix

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

      export function fromRomanNumerals(txt: string): number {
        var s = ROMAN_SYMBOLS.length-1;
        var n = txt.search(/^\s*-/) >= 0, a = 0;
        var txt = txt.replace(/\W/g, '').toUpperCase();
        for (var i=0, I=txt.length; i<I;  i += ROMAN_SYMBOLS[s].length) {
      Severity: Minor
      Found in src/index.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

          if (x % (i-1)===0) return i-1;
      Severity: Major
      Found in src/index.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            if (x % (i+1)===0) return i+1;
        Severity: Major
        Found in src/index.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

            return x;
          Severity: Major
          Found in src/index.ts - About 30 mins to fix

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

            export function prevPow(x: number, n: number): number {
              if (x<=1) return 0;
              var p = Math.floor(Math.log(x) / Math.log(n));
              return  Math.pow(n, p);
            }
            Severity: Major
            Found in src/index.ts and 1 other location - About 2 hrs to fix
            src/index.ts on lines 339..343

            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 87.

            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

            export function nextPow(x: number, n: number): number {
              if (x<=0) return 1;
              var p = Math.ceil(Math.log(x) / Math.log(n));
              return  Math.pow(n, p);
            }
            Severity: Major
            Found in src/index.ts and 1 other location - About 2 hrs to fix
            src/index.ts on lines 326..330

            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 87.

            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

              for (var i=6, I=Math.sqrt(x)+1; x>1 && i<=I; i+=6) {
                x = pushPrimeExponentialTo$(a, x, i-1);
                x = pushPrimeExponentialTo$(a, x, i+1);
              }
            Severity: Major
            Found in src/index.ts and 1 other location - About 2 hrs to fix
            src/index.ts on lines 473..476

            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 86.

            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

              for (var i=6, I=Math.sqrt(x)+1; x>1 && i<=I; i+=6) {
                x = pushPrimeFactorTo$(a, x, i-1);
                x = pushPrimeFactorTo$(a, x, i+1);
              }
            Severity: Major
            Found in src/index.ts and 1 other location - About 2 hrs to fix
            src/index.ts on lines 506..509

            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 86.

            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.
            Invalid

            export function sum(...xs: number[]): number {
              var a = 0;
              for (var x of xs)
                a += x;
              return a;
            Severity: Minor
            Found in src/index.ts and 1 other location - About 40 mins to fix
            src/index.ts on lines 692..697

            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 49.

            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.
            Invalid

            export function product(...xs: number[]): number {
              var a = 1;
              for (var x of xs)
                a *= x;
              return a;
            Severity: Minor
            Found in src/index.ts and 1 other location - About 40 mins to fix
            src/index.ts on lines 679..684

            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 49.

            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.
            Invalid

            export function floor(x: number, pre: number=1): number {
              return Math.floor(x/pre)*pre;
            }
            Severity: Minor
            Found in src/index.ts and 2 other locations - About 35 mins to fix
            src/index.ts on lines 131..133
            src/index.ts on lines 141..143

            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 46.

            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.
            Invalid

            export function round(x: number, pre: number=1): number {
              return Math.round(x/pre)*pre;
            }
            Severity: Minor
            Found in src/index.ts and 2 other locations - About 35 mins to fix
            src/index.ts on lines 121..123
            src/index.ts on lines 131..133

            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 46.

            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.
            Invalid

            export function ceil(x: number, pre: number=1): number {
              return Math.ceil(x/pre)*pre;
            }
            Severity: Minor
            Found in src/index.ts and 2 other locations - About 35 mins to fix
            src/index.ts on lines 121..123
            src/index.ts on lines 141..143

            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 46.

            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

            There are no issues that match your filters.

            Category
            Status