RosettaCodeData/Task/Identity-matrix/JavaScript/identity-matrix-2.js

14 lines
247 B
JavaScript

(() => {
// idMatrix :: Int -> [[0 | 1]]
const idMatrix = n => Array.from({
length: n
}, (_, i) => Array.from({
length: n
}, (_, j) => i !== j ? 0 : 1));
// TEST
return idMatrix(5);
})();