File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed
fraction-addition-and-subtraction Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,7 @@ export class Fraction {
2
2
sign : number ;
3
3
molecular : number ;
4
4
denominator : number ;
5
- toString ( ) {
6
- return `${
7
- this . sign < 0 ? "-" : ""
8
- } ${ this . molecular } /${ this . denominator } `;
9
- }
5
+
10
6
constructor ( {
11
7
sign = "+" ,
12
8
molecular = 1 ,
@@ -24,3 +20,6 @@ export class Fraction {
24
20
this . denominator = Math . abs ( Number ( denominator ) ) ;
25
21
}
26
22
}
23
+ export function FractionToString ( f : Fraction ) {
24
+ return `${ f . sign < 0 ? "-" : "" } ${ f . molecular } /${ f . denominator } ` ;
25
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { greatestCommonDivisor } from "../max-points-on-a-line/greatest_common_d
2
2
import { deduplication } from "./deduplication.ts" ;
3
3
import { Fraction } from "./Fraction.ts" ;
4
4
import { parseFraction } from "./parseFraction.ts" ;
5
+ import { FractionToString } from "./Fraction.ts" ;
5
6
6
7
function fractionAddition ( expression : string ) : string {
7
8
const fractions = parseFraction ( expression ) ;
@@ -14,9 +15,11 @@ function fractionAddition(expression: string): string {
14
15
. reduce ( ( a , b ) => a + b ) ;
15
16
const gcd = greatestCommonDivisor ( molecular , denominator ) ;
16
17
17
- return new Fraction ( {
18
- denominator : denominator / gcd ,
19
- molecular : molecular / gcd ,
20
- } ) . toString ( ) ;
18
+ return FractionToString (
19
+ new Fraction ( {
20
+ denominator : denominator / gcd ,
21
+ molecular : molecular / gcd ,
22
+ } ) ,
23
+ ) ;
21
24
}
22
25
export default fractionAddition ;
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ export default function rotatedDigits(n: number): number {
2
2
if ( typeof cache [ n ] !== "undefined" ) return cache [ n ] ;
3
3
4
4
for ( let i = 1 ; i <= 10000 ; i ++ ) {
5
- cache [ i ] = cache [ i - 1 ] + Number ( isrotatedDigit ( i ) ) ;
5
+ cache [ i ] = cache [ i - 1 ] + Number ( isRotatedDigit ( i ) ) ;
6
6
}
7
7
8
8
return cache [ n ] ?? 0 ;
9
9
}
10
- function isrotatedDigit ( n : number ) {
10
+ function isRotatedDigit ( n : number ) {
11
11
const map : Record < string | number , number > = {
12
12
0 : 0 ,
13
13
1 : 1 ,
You can’t perform that action at this time.
0 commit comments