npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

class-matrix

v1.2.0

Published

matrix, class for two dimension arrays

Downloads

22

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

$ 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);

| 0 | 1 | 2 | |---|---|---| | 1 | 2 | 3 | | 2 | 3 | 4 |

console.log(matrixA.getValueOf([2,2]));

4

matrixA.setValueOf([2,2],9);
console.log(matrixA.value);

| 0 | 1 | 2 | |---|---|---| | 1 | 2 | 3 | | 2 | 3 | 9 |

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

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!