Skip to content

Commit 6e54c7c

Browse files
Order the matrix getAll() method's results to make them easier to test
1 parent d32c976 commit 6e54c7c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/matrix.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,20 @@ export class SparseMatrix {
8383
}
8484
}
8585

86-
getAll(): { value: number; row: number; col: number }[] {
87-
let rowColValues: Entry[] = [];
86+
getAll(ordered = true): { value: number; row: number; col: number }[] {
87+
const rowColValues: Entry[] = [];
8888
this.entries.forEach((value) => {
8989
rowColValues.push(value);
9090
});
91+
if (ordered) { // Ordering the result isn't required for processing but it does make it easier to write tests
92+
rowColValues.sort((a, b) => {
93+
if (a.row === b.row) {
94+
return a.col - b.col;
95+
} else {
96+
return a.row - b.row;
97+
}
98+
});
99+
}
91100
return rowColValues;
92101
}
93102

0 commit comments

Comments
 (0)