Class Fraction

Fraction represents a rational number.

Hierarchy

  • Fraction

Constructors

  • Set the numerator and denominator.

    Parameters

    • Optional numerator: number
    • Optional denominator: number

    Returns Fraction

Properties

denominator: number = 1
numerator: number = 1

Accessors

  • get CATEGORY(): string
  • Returns string

Methods

  • Add value of another fraction.

    Parameters

    • param1: number | Fraction = 0
    • param2: number = 1

    Returns Fraction

  • Divide by value of another Fraction.

    Parameters

    • param1: number | Fraction = 1
    • param2: number = 1

    Returns Fraction

  • Simplify both sides and check if they are equal.

    Parameters

    Returns boolean

  • Greater than operator.

    Parameters

    Returns boolean

  • Greater than or equals operator.

    Parameters

    Returns boolean

  • Less than operator.

    Parameters

    Returns boolean

  • Less than or equals operator.

    Parameters

    Returns boolean

  • Multiply by value of another fraction.

    Parameters

    • param1: number | Fraction = 1
    • param2: number = 1

    Returns Fraction

  • Parse a fraction string.

    Parameters

    • str: string

    Returns Fraction

  • Return the integer component (eg. 5/2 => 2).

    Returns number

  • Return the remainder component (eg. 5/2 => 1).

    Returns number

  • Set the numerator and denominator.

    Parameters

    • numerator: number = 1
    • denominator: number = 1

    Returns Fraction

  • Simplify numerator and denominator using GCD.

    Returns Fraction

  • Substract value of another fraction.

    Parameters

    • param1: number | Fraction = 0
    • param2: number = 1

    Returns Fraction

  • Return string representation in mixed form.

    Returns string

  • Return a simplified string respresentation.

    Returns string

  • Return a raw string representation (eg. "5/2").

    Returns string

  • Return the value of the fraction.

    Returns number

  • GCD: Greatest common divisor using the Euclidean algorithm. Note: GCD(0, 0) => 0 and GCD(0, n) => n.

    Parameters

    • a: number
    • b: number

    Returns number

  • LCM: Lowest common multiple.

    Parameters

    • a: number
    • b: number

    Returns number

  • Lowest common multiple for more than two numbers.

    Parameters

    • args: number[]

    Returns number