We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 22a49a1 commit e80f453Copy full SHA for e80f453
src/index.js
@@ -67,13 +67,13 @@ export class SparseMatrix {
67
* @returns {number[][]}
68
*/
69
to2DArray() {
70
- const copy = new Array(this.rows);
71
- for (let i = 0; i < this.rows; i++) {
72
- copy[i] = new Array(this.columns);
73
- for (let j = 0; j < this.columns; j++) {
74
- copy[i][j] = this.get(i, j);
75
- }
76
+ const copy = Array.from({ length: this.rows }, () =>
+ new Array(this.columns).fill(0),
+ );
+ this.withEachNonZero((i, j, v) => {
+ copy[i][j] = v;
+ });
+
77
return copy;
78
}
79
0 commit comments