CARVIEW |
JavaScript Matrix - School Programming
Here we will cover the quiz related to JavaScript Matrix to clear all your concepts.
Question 1
What is a matrix in JavaScript?
a) A data structure that contains a collection of elements arranged in rows and columns
b) A type of function that takes in an array as input and returns a new array
c) A built-in class that allows you to manipulate strings
Question 2
What is the result of the following matrix subtraction?
let matrix1 = [[1, 2], [3, 4]];
let matrix2 = [[4, 3], [2, 1]];
matrix1 - matrix2
a) An error will be thrown
b) [[-3, -1], [1, 3]]
c) [[-3, -5], [1, 3]]
Question 3
How do you find the determinant of a matrix in JavaScript?
a) By using the "determinant()" method
b) By iterating through each element and calculating the determinant
c) JavaScript does not have a built-in function for calculating determinants
Question 4
What is the identity matrix?
a) A matrix with all elements equal to zero
b) A matrix with all elements equal to one
c) A square matrix with ones on the diagonal and zeros elsewhere
Question 5
How do you transpose a matrix in JavaScript?
a) By using the "transpose()" method
b) By iterating through each element and swapping rows and columns
c) By using the "reverse()" method
Question 6
What is the result of the following matrix multiplication?
let matrix1 = [[1, 2, 3], [4, 5, 6]];
let matrix2 = [[7, 8], [9, 10], [11, 12]];
matrix1 * matrix2
a) An error will be thrown
b) [[58, 64], [139, 154]]
c) [[7, 8, 9], [12, 15, 18], [11, 12, 13]]
Question 7
How do you add two matrices in JavaScript?
a) By using the "+" operator
b) By iterating through each element and adding them together
c) Matrices cannot be added in JavaScript
Question 8
How do you access the element in the second row and third column of the following matrix?
let matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
a) matrix[1, 2]
b) matrix[2][1]
c) matrix[3][2]
Question 9
How do you declare a matrix in JavaScript?
a) let matrix = [1, 2, 3, 4];
b) let matrix = [[1, 2], [3, 4]];
c) let matrix = {1: [1, 2], 2: [3, 4]};
Question 10
What is the output of the following code?
const matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
const rowSum = matrix.map(row => row.reduce((acc, val) => acc + val));
console.log(rowSum);
[6, 15, 24]
[12, 15, 18]
[3, 12, 21]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
There are 17 questions to complete.