Skip to content

Error in Least Common Multiple algorithm #943

Open
@gkwaerp

Description

@gkwaerp

Brief Intro

https://github.com/raywenderlich/swift-algorithm-club/tree/master/GCD
The code fails (fatalError) in various valid scenarios, e.g. lcm(3, 4) --> should be 12.

More Details

guard (m & n) != 0 else { throw LCMError.divisionByZero }

This is not a division by zero check, nor is it a relevant check for this algorithm.
Would recommend changing to e.g.

guard m > 0, n > 0 else { throw LCMError.nonPositiveNumbers } //Must be added to LCMError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions