Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active October 6, 2022 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/fcd5e209ccca8359e852b986cc5b47ea to your computer and use it in GitHub Desktop.
Save McLarenCollege/fcd5e209ccca8359e852b986cc5b47ea to your computer and use it in GitHub Desktop.
Copy Without Row and Column

Copy Without Row and Column

Create a function which takes a rectangular matrix, and a row and column index, then returns a copy of that matrix with given row and column removed.

Note: The input matrix should not be modified

Example 1

let matrix1 = [
    [2, 7, 9, 2],
    [8, 0, 7, 1],
    [8, 8, 0, 8]
];

// Should return:
// [[2, 7, 2], [8, 8, 8]]
copyWithoutRowAndColumn(matrix1, 1, 2);

Example 2

let matrix2 = [
  ['a', undefined, 6],
  [true, 'x', [false]]
];


// Should return:
// [['x', [false]]]
copyWithoutRowAndColumn(matrix2, 0, 0);

CODE TEMPLATE


function copyWithoutRowAndColumn(matrix, row, col){
// write your code here
}
let matrix1 = [
    [2, 7, 9, 2],
    [8, 0, 7, 1],
    [8, 8, 0, 8]
];

console.log(copyWithoutRowAndColumn(matrix1, 1, 2));
let matrix2 = [
  ['a', undefined, 6],
  [true, 'x', [false]]
];
console.log(copyWithoutRowAndColumn(matrix2, 0, 0));

Please watch this video for a hint for solving the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment