Skip to content

Commit

Permalink
fix: styling issues picked up by Travis CI
Browse files Browse the repository at this point in the history
  • Loading branch information
zafarali authored and targos committed Nov 23, 2016
1 parent 90532ef commit f211a1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
27 changes: 11 additions & 16 deletions src/abstractMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -1509,41 +1509,36 @@ function abstractMatrix(superCtor) {
* Calculates and returns the determinant of a matrix as a Number
* @example
* new Matrix([[1,2,3], [4,5,6]]).det()
*
* @return {number}
*/
det(){
if(this.isSquare()){
if(this.columns === 2){
// 2 x 2 matrix
var a,b,c,d;
det() {
if (this.isSquare()) {
var a, b, c, d;
if (this.columns === 2) {
// 2 x 2 matrix
a = this.get(0, 0);
b = this.get(0, 1);
c = this.get(1, 0);
d = this.get(1, 1);

return a * d - ( b * c);

}else if(this.columns === 3){
return a * d - (b * c);
} else if (this.columns === 3) {
// 3 x 3 matrix
var subMatrix0, subMatrix1, subMatrix2;
var a, b, c;

subMatrix0 = this.selection([1, 2], [1, 2]);
subMatrix1 = this.selection([1, 2], [0, 2]);
subMatrix2 = this.selection([1, 2], [0, 1]);
a = this.get(0, 0);
b = this.get(0, 1);
c = this.get(0, 2);

return a * subMatrix0.det() - b * subMatrix1.det() + c * subMatrix2.det();

}else{
return a * subMatrix0.det() - b * subMatrix1.det() + c * subMatrix2.det();
} else {
// general purpose determinant using the LU decomposition
return new LuDecomposition(this, {skipCheck:true}).determinant;
return new LuDecomposition(this, {skipCheck: true}).determinant;
}

}else{
} else {
throw Error('Determinant can only be calculated for a square matrix.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dc/lu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function LuDecomposition(matrix, options) {

options = options || {};

if(!options.skipCheck){
if (!options.skipCheck) {
matrix = Matrix.checkMatrix(matrix);
}

Expand Down
6 changes: 3 additions & 3 deletions test/matrix/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('utility methods', function () {
transpose[2][1].should.equal(matrix[1][2]);
});

it('determinant', function(){
it('determinant', function () {
var determinant = matrix.det();
determinant.should.equal(-18);
var subMatrix = matrix.selection([1,2], [1,2]);
determinant = subMatrix.det()
var subMatrix = matrix.selection([1, 2], [1, 2]);
determinant = subMatrix.det();
determinant.should.equal(-9);
});
it('transpose rectangular', function () {
Expand Down

0 comments on commit f211a1f

Please sign in to comment.