Identity matrix: Difference between revisions

m
(Frink)
Line 1,665:
 
===ES6===
 
<lang JavaScript>(() => {
 
// idMatrixidentityMatrix :: Int -> [[0 | 1]Int]
const idMatrixidentityMatrix = n => Array.from({
Array.from({
length: n
}, (_, i) => Array.from({
Line 1,675:
}, (_, j) => i !== j ? 0 : 1));
 
// show :: a -> String
const show = JSON.stringify;
 
// ----------------------- TEST ------------------------
// TEST
return idMatrixidentityMatrix(5)
.map(showJSON.stringify)
.join('\n');
})();</lang>
 
{{Out}}
<pre>[1,0,0,0,0]
9,655

edits