10. Write a JavaScript function which returns the n rows by n columns identity matrix. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

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

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

28th Dec 2016, 8:22 PM
Nashwan Aziz
Nashwan Aziz - avatar
1 Answer
0
<script> function myFunc(n) { "use strict"; var arr = [], i, j; for (i = 0; i < n; i += 1) { arr[i] = []; for (j = 0; j < n; j += 1) { arr[i][j] = {i: i, j: j}; } } return arr; } </script>
29th Dec 2016, 12:29 AM
zakaria mouhid
zakaria mouhid - avatar