Skip to content

Commit

Permalink
added some explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
MegPunyu committed Oct 18, 2022
1 parent 5f137b0 commit 88f006f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
},
"type": "module",
"types": "dist/index.d.ts",
"version": "2.1.0"
"version": "2.1.1"
}
34 changes: 33 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,36 @@ half.lt(half); // false

// <=
half.le(half); // true
```
```

### destructive methods
Methods whose names end in $ modify objects. These methods are more efficient than the methods introduced above since they do not copy objects internally.

```javascript
const half1 = new Frac(1, 2); // (1 / 2)
const half2 = new Frac(2, 4); // (2 / 4)

half1.add$(half2); // (1 / 1)

half1; // (1 / 1) <- replaced by the result of an operation
half2; // (2 / 4)
```

```javascript
const frac = new Frac("(1 / (1 / 2))"); // (1 / (1 / 2))

frac.reduce$(); // (2 / 1)

frac; // (2 / 1) <- replaced by the result of an operation
```

Methods whose names end in $$ modify arguments.
```javascript
const half1 = new Frac(1, 2); // (1 / 2)
const half2 = new Frac(2, 4); // (2 / 4)

half1.add$$(half2); // (1 / 1)

half1; // (1 / 1) <- replaced by the result of an operation
half2; // (1 / 2) <- reduced
```
4 changes: 4 additions & 0 deletions src/Frac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ export default class Frac {
/**
* Returns a string representation of the fraction.
*
* @param spaces number of whitespaces
* @param indent indent size of the first line
* @param indentLevel indent level
*
* @example
* const half = new Frac(1, 2); // (1 / 2)
*
Expand Down

0 comments on commit 88f006f

Please sign in to comment.