File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ class Matrix {
2+ constructor ( row , coloumn ) {
3+ this . rows = row
4+ this . col = coloumn
5+ this . matrix = [ ]
6+ for ( let i = 0 ; i < this . rows ; i ++ ) {
7+ this . matrix [ i ] = [ ]
8+ for ( let k = 0 ; k < this . col ; k ++ ) {
9+ this . matrix [ i ] [ k ] = 0
10+ }
11+ }
12+ console . table ( this . matrix )
13+ }
14+ fill ( n ) {
15+ for ( let i = 0 ; i < this . rows ; i ++ ) {
16+ this . matrix [ i ] = [ ]
17+ for ( let k = 0 ; k < this . col ; k ++ ) {
18+ this . matrix [ i ] [ k ] = n
19+ }
20+
21+ }
22+ console . table ( this . matrix )
23+ }
24+ generate ( ) {
25+ for ( let i = 0 ; i < this . rows ; i ++ ) {
26+ this . matrix [ i ] = [ ]
27+ for ( let k = 0 ; k < this . col ; k ++ ) {
28+ this . matrix [ i ] [ k ] = Math . floor ( Math . random ( ) * 10 )
29+ }
30+
31+ }
32+ // console.table(this.matrix)
33+ }
34+
35+ }
36+
37+
38+ let t = new Matrix ( 3 , 2 )
39+ let j = ( t . Matrix )
40+ let add = k . fill ( 5 )
41+ // simple program to generate javascript matrix
You can’t perform that action at this time.
0 commit comments