What's the preferred way of comparing 2 Fractions?
I'm interested in what's the preferred way of comparing 2 fractionals. I see there is an equals method, but I'm interested in the `>`, `<`, `>=` and `<=` operators.
From what I can see looking at the API, this is the most straightforward way of doing this:
```ts
const a = new Fraction(1, 2)
const b = new Fraction(1, 2)
if (a.valueOf() > b.valueOf()) {
// ...
}
```
Is this the preferred way to compare 2 Fractionals?
I see there is also this:
```ts
if (a.compare(b) < 0) {
// ...
}
```
But this is not that great readability-wise.
关闭于 2024-10-30 7 条评论