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

18 lines
346 B
JavaScript
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
(() => {
// idMatrix :: Int -> [[0 | 1]]
const idMatrix = n => Array.from({
length: n
}, (_, i) => Array.from({
length: n
}, (_, j) => i !== j ? 0 : 1));
2017-09-23 10:01:46 +02:00
// show :: a -> String
const show = JSON.stringify;
2016-12-05 22:15:40 +01:00
// TEST
2017-09-23 10:01:46 +02:00
return idMatrix(5)
.map(show)
.join('\n');
2016-12-05 22:15:40 +01:00
})();