Matrix
This commit is contained in:
26
typescript/matrix/matrix.ts
Normal file
26
typescript/matrix/matrix.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export class Matrix {
|
||||
private _rows: number[][];
|
||||
private _columns: number[][];
|
||||
|
||||
constructor(matrix: string) {
|
||||
this._rows = matrix
|
||||
.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((row) =>
|
||||
row
|
||||
.split(" ")
|
||||
.filter(Boolean)
|
||||
.map((v) => parseInt(v, 10))
|
||||
);
|
||||
|
||||
this._columns = this.rows[0].map((_, i) => this.rows.map((row) => row[i]));
|
||||
}
|
||||
|
||||
get rows(): number[][] {
|
||||
return this._rows;
|
||||
}
|
||||
|
||||
get columns(): number[][] {
|
||||
return this._columns;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user