Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Identity-matrix/JavaScript/identity-matrix-1.js
Normal file
8
Task/Identity-matrix/JavaScript/identity-matrix-1.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
function idMatrix(n) {
|
||||
return Array.apply(null, new Array(n))
|
||||
.map(function (x, i, xs) {
|
||||
return xs.map(function (_, k) {
|
||||
return i === k ? 1 : 0;
|
||||
})
|
||||
});
|
||||
}
|
||||
16
Task/Identity-matrix/JavaScript/identity-matrix-2.js
Normal file
16
Task/Identity-matrix/JavaScript/identity-matrix-2.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(() => {
|
||||
|
||||
// identityMatrix :: Int -> [[Int]]
|
||||
const identityMatrix = n =>
|
||||
Array.from({
|
||||
length: n
|
||||
}, (_, i) => Array.from({
|
||||
length: n
|
||||
}, (_, j) => i !== j ? 0 : 1));
|
||||
|
||||
|
||||
// ----------------------- TEST ------------------------
|
||||
return identityMatrix(5)
|
||||
.map(JSON.stringify)
|
||||
.join('\n');
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue