Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Maths/RowEchelon.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const rowEchelon = (matrix) => {

let numRows = matrix.length
let numCols = matrix[0].length
let result = matrix
let result = matrix.map((row) => [...row])

// Iterate through the rows (i) and columns (j) of the matrix.
for (let i = 0, j = 0; i < numRows && j < numCols; ) {
Expand Down
12 changes: 12 additions & 0 deletions Maths/test/RowEchelon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ describe('Determinant', () => {
])('Should return the error message.', (matrix, expected) => {
expect(() => rowEchelon(matrix)).toThrowError(expected)
})

test('Should not mutate the input matrix.', () => {
const matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 10]
]
const original = matrix.map((row) => [...row])
const result = rowEchelon(matrix)
expect(matrix).toEqual(original)
expect(result).not.toBe(matrix)
})
})
Loading