1.2.0 • Published 2 years ago

class-matrix v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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

$ npm i class-matrix    

< Use - node.js >

  • common JS
const Matrix = require('class-matrix');
  • ESM
import Matrix from 'class-matrix';

< Use - browser >

  • Link in \<head> tag
<script src="./matrix-js-link.min.js"></script>
  • import in a module file

import { Matrix } from './matrix-js-module.min.js';

< Methods >

  • INIT & VALUE
new Matrix
.row
.column
getter value
setter value
getValueOf()
setValueOf()   
  • CHECK & FIND
Matrix.isMatrix()
at()
find()
findLast()
findIndex()
findLastIndex()
indexOf()
lastIndexOf()
includes()
  • NEW STRUCTURE
concat()
flat()
join()
toString()
slice()
  • ITERATE
forEach()
map()
reduce()
reduceRight()
filter()
every()
some()
  • CHANGE IN PLACE
fill()
pop()
push()
shift()
unshift()
splice()
sort()
reverse()
copyWithin()
  • CHANGE IN PLACE
fill()
pop()
push()
shift()
unshift()
splice()
sort()
reverse()
copyWithin()
  • GENERATOR
keys()
values()
entries()
  • MATH
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 >

let matrixA = new Matrix(3,3).fill((el,[i,j])=>i+j);
012
123
234
console.log(matrixA.getValueOf([2,2]));

4

matrixA.setValueOf([2,2],9);
console.log(matrixA.value);
012
123
239
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
01
23
45

row = 2, column = 2

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!

1.2.0

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago