Skip to content

Commit

Permalink
feat: determinant
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryGogonis committed Jun 25, 2017
1 parent c18f6e2 commit 01a7615
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class Matrix extends Map {
]
return `matrix(${values.join()})`
}

/**
* @return {number} determinant of the current matrix
*/
determinant () {
return (this.get('a') * this.get('d')) - (this.get('b') * this.get('c'))
}
}

export default Matrix
6 changes: 6 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ describe('toString', () => {
expect(str).toBe('matrix(6,5,4,3,2,1)')
})
})

describe('determinant', () => {
expect(mockMatrix.determinant()).toBe(-2)
expect(new Matrix().determinant()).toBe(1)
expect(new Matrix(1, 1, 1, 1, 0, 0).determinant()).toBe(0)
})

0 comments on commit 01a7615

Please sign in to comment.