+ 1

1

10. Write a JavaScript function which returns the n rows by n columns identity matrix.

10th Dec 2016, 7:41 PM
Nashwan Aziz
Nashwan Aziz - avatar
6 Antworten
+ 3
is in put the number n?
10th Dec 2016, 8:03 PM
manish rawat
manish rawat - avatar
+ 2
bro whats input?
10th Dec 2016, 8:03 PM
manish rawat
manish rawat - avatar
+ 2
function identityMatrix(n) { var a = []; for(i=0;i<n;i++) { for(j=0;j<n;j++) { a[i][j] = (i == j) ? 1 : 0; } } return a; }
10th Dec 2016, 8:05 PM
Rishi Anand
Rishi Anand - avatar
+ 1
var n = 4; var newArr = function () { var result, l, i; if(arguments.length > 0) { l = [].slice.call(arguments, 0, 1)[0]; result = new Array(l); for(i = 0; i < l; i++) { result[i] = newArr.apply(null, [].slice.call(arguments, 1)); } } else { return 0; } return result; }; function matIdentity(n) { var matrix = newArr(n,n) for (i = 0; i < n; ++i) { matrix[i][i] = 1; } return matrix; } alert(matIdentity(n))
10th Dec 2016, 8:17 PM
Kerrash
Kerrash - avatar
0
10. Write a JavaScript function which returns the n rows by n columns identity matrix.
10th Dec 2016, 7:41 PM
Nashwan Aziz
Nashwan Aziz - avatar
0
n
10th Dec 2016, 8:05 PM
Nashwan Aziz
Nashwan Aziz - avatar