Skip to content

Commit 4f46824

Browse files
committed
extend computation
1 parent ab70949 commit 4f46824

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

src/minus.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,32 @@ const {_throwArgumentsError} = require('./utils');
44

55
/**
66
* matrix相减
7+
* @param {Matrix} args
8+
* @return {Matrix}
9+
* **/
10+
Matrix.minus = function(...args){
11+
if(args.length < 2) _throwArgumentsError();
12+
if(args.length === 2) return minusTwo(args[0], args[1]);
13+
return Matrix.minus(minusTwo(args[0], args[1]), ...args.slice(2));
14+
};
15+
16+
/**
17+
* Matrix相减
18+
* @param {Matrix} args
19+
* @return {Matrix}
20+
* **/
21+
Matrix.prototype.minus = function(...args){
22+
return Matrix.minus(this, ...args);
23+
};
24+
25+
26+
/**
27+
* 两个matrix相减
728
* @param {Matrix} a
829
* @param {Matrix} b
930
* @return {Matrix}
1031
* **/
11-
Matrix.minus = function (a, b) {
32+
function minusTwo(a, b) {
1233
if(!(a instanceof Matrix) || !(b instanceof Matrix)) _throwArgumentsError();
1334
if(a.column !== b.column || a.row !== b.row) _throwArgumentsError();
1435

@@ -25,13 +46,4 @@ Matrix.minus = function (a, b) {
2546
let m = new Matrix();
2647
m._data = _data;
2748
return m;
28-
};
29-
30-
/**
31-
* Matrix相减
32-
* @param {Matrix} matrix
33-
* @return {Matrix}
34-
* **/
35-
Matrix.prototype.minus = function(matrix){
36-
return Matrix.minus(this, matrix);
37-
};
49+
}

src/plus.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,32 @@ const {_throwArgumentsError} = require('./utils');
33

44
/**
55
* matrix相加
6+
* @param {Matrix} args
7+
* @return {Matrix}
8+
* **/
9+
Matrix.add = Matrix.plus = function(...args){
10+
if(args.length < 2) _throwArgumentsError();
11+
if(args.length === 2) return plusTwo(...args);
12+
return Matrix.add(plusTwo(args[0], args[1]), ...args.slice(2));
13+
};
14+
15+
/**
16+
* Matrix相加
17+
* @param {Matrix} args
18+
* @return {Matrix}
19+
* **/
20+
Matrix.prototype.add = Matrix.prototype.plus = function(...args){
21+
return Matrix.add(this, ...args);
22+
};
23+
24+
25+
/**
26+
* 两个Matrix相加
627
* @param {Matrix} a
728
* @param {Matrix} b
829
* @return {Matrix}
930
* **/
10-
Matrix.add = Matrix.plus = function (a, b) {
31+
function plusTwo(a, b) {
1132
if(!(a instanceof Matrix) || !(b instanceof Matrix)) _throwArgumentsError();
1233
if(a.column !== b.column || a.row !== b.row) _throwArgumentsError();
1334

@@ -24,13 +45,4 @@ Matrix.add = Matrix.plus = function (a, b) {
2445
let m = new Matrix();
2546
m._data = _data;
2647
return m;
27-
};
28-
29-
/**
30-
* Matrix相加
31-
* @param {Matrix} matrix
32-
* @return {Matrix}
33-
* **/
34-
Matrix.prototype.add = Matrix.prototype.plus = function(matrix){
35-
return Matrix.add(this, matrix);
36-
};
48+
}

0 commit comments

Comments
 (0)