FUNDAMENTALS
ARRAYS
MATRIX
LINEAR ALGEBRA
MATHEMATICS
LANGUAGE FEATURES
Create an identity matrix of the specified size( >= 0).
Some examples:
(1) => [[1]]
(2) => [ [1,0],
[0,1] ]
[ [1,0,0,0,0],
[0,1,0,0,0],
(5) => [0,0,1,0,0],
[0,0,0,1,0],
[0,0,0,0,1] ]
const getMatrix = number => {
const result = []
for (let i = 0; i < number; i++) {
const subArray = Array(number).fill(0)
subArray[i] = 1
result.push(subArray)
}
return result
}