https://github.com/ybribri/matrix
class for two dimension array
https://github.com/ybribri/matrix
2d 2darrays array-manipulations class matrix node-js pure-javascript
Last synced: about 1 month ago
JSON representation
class for two dimension array
- Host: GitHub
- URL: https://github.com/ybribri/matrix
- Owner: ybribri
- License: apache-2.0
- Created: 2022-10-13T14:00:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-21T11:29:40.000Z (over 3 years ago)
- Last Synced: 2025-02-11T06:05:23.673Z (over 1 year ago)
- Topics: 2d, 2darrays, array-manipulations, class, matrix, node-js, pure-javascript
- Language: JavaScript
- Homepage:
- Size: 137 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Matrix - class for two dimension array
> V1.20 : methods for math added. Refer to the function list below.
* Easy as original Javascript prototype functions
* All the same prototype functions of array for two dimensional arrays with adjusted arguments
* Added functions only for this class
### < Install >
needed only for node.js
```bash
$ npm i class-matrix
```
### < Use - node.js >
* *common JS*
```javascript
const Matrix = require('class-matrix');
````
* *ESM*
```javascript
import Matrix from 'class-matrix';
```
### < Use - browser >
* *Link in \ tag*
```html
```
* *import in a module file*
```javascript
import { Matrix } from './matrix-js-module.min.js';
```
## < Methods >
* **INIT & VALUE**
```javascript
new Matrix
.row
.column
getter value
setter value
getValueOf()
setValueOf()
```
* **CHECK & FIND**
```javascript
Matrix.isMatrix()
at()
find()
findLast()
findIndex()
findLastIndex()
indexOf()
lastIndexOf()
includes()
```
* **NEW STRUCTURE**
```javascript
concat()
flat()
join()
toString()
slice()
```
* **ITERATE**
```javascript
forEach()
map()
reduce()
reduceRight()
filter()
every()
some()
```
* **CHANGE IN PLACE**
```javascript
fill()
pop()
push()
shift()
unshift()
splice()
sort()
reverse()
copyWithin()
```
* **CHANGE IN PLACE**
```javascript
fill()
pop()
push()
shift()
unshift()
splice()
sort()
reverse()
copyWithin()
```
* **GENERATOR**
```javascript
keys()
values()
entries()
```
* **MATH**
```javascript
det()
cofactors()
transpose()
adjoint()
inverse()
add()
subtract()
multiply()
divide()
```
> All the prototype functions are rebuilt for this class.\
> In most cases, an index in callback function is seperated into a row index and a column index\
> Some prototype functions are added only for matrix class
## < EXAMPLE >
```javascript
let matrixA = new Matrix(3,3).fill((el,[i,j])=>i+j);
```
| 0 | 1 | 2 |
|---|---|---|
| **1** | **2** | **3** |
| **2** | **3** | **4** |
```javascript
console.log(matrixA.getValueOf([2,2]));
```
4
```javascript
matrixA.setValueOf([2,2],9);
console.log(matrixA.value);
```
| 0 | 1 | 2 |
|---|---|---|
| **1** | **2** | **3** |
| **2** | **3** | **9** |
```javascript
matrixA.value = [[0,1],[2,3],[4,5]];
console.log(matrixA.value);
console.log(`row = ${matrixA.row}, column = ${matrixA.column}`);
// if you set value directly, it would change the structure of the matrix
```
| 0 | 1 |
|---|---|
| **2** | **3** |
| **4** | **5** |
row = 2, column = 2
```javascript
matrixA.forEach((el, [i,j])=>{
console.log(`[${i},${j}] = ${el}`);
});
```
[0,0] = 0
[0,1] = 1
[0,2] = 2
[1,0] = 1
[1,1] = 2
[1,2] = 3
[2,0] = 2
[2,1] = 3
[2,2] = 4
## [Click here for more details of each methods!](https://ybrians.cafe24.com/matrix/)