Skip to content

Commit faafe65

Browse files
committed
Make it into a library
1 parent 69c8434 commit faafe65

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

JavaScript/fraction.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,4 @@ Fraction.prototype.div = function (f) {
4343
return new Fraction(this._numerator*f._denominator, this._denominator*f._numerator);
4444
};
4545

46-
var onehalf = new Fraction(1, 2);
47-
var twothird = new Fraction(2, 3);
48-
console.log(onehalf.toString() + ' + ' + twothird.toString() + ' = ' + onehalf.add(twothird).toString());
49-
console.log(onehalf.toString() + ' / ' + twothird.toString() + ' = ' + onehalf.div(twothird).toString());
50-
51-
var almost_pi = new Fraction(22, 7);
52-
var two = new Fraction(2, 1);
53-
console.log(almost_pi.toString() + ' * ' + two.toString() + ' = ' + almost_pi.mul(two));
54-
55-
var f = onehalf.div(twothird);
56-
console.log('f = ' + f.toString() + ' ~= ' + f.toNumber());
46+
module.exports = Fraction;

JavaScript/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const Fraction = require('./fraction');
2+
3+
var onehalf = new Fraction(1, 2);
4+
var twothird = new Fraction(2, 3);
5+
console.log(onehalf.toString() + ' + ' + twothird.toString() + ' = ' + onehalf.add(twothird).toString());
6+
console.log(onehalf.toString() + ' / ' + twothird.toString() + ' = ' + onehalf.div(twothird).toString());
7+
8+
var almost_pi = new Fraction(22, 7);
9+
var two = new Fraction(2, 1);
10+
console.log(almost_pi.toString() + ' * ' + two.toString() + ' = ' + almost_pi.mul(two));
11+
12+
var f = onehalf.div(twothird);
13+
console.log('f = ' + f.toString() + ' ~= ' + f.toNumber());

0 commit comments

Comments
 (0)