Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.5 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
5a23c84252665b21eecc7eb1 身份矩阵 5 identity-matrix

--description--

单位矩阵是大小为\n \次n \)的方阵,其中对角元素都是1 s1所有其他元素都是0 s。 \ begin {bmatrix} 100 \ cr 010 \ cr 001 \ cr \ end {bmatrix}编写一个以数字'n'作为参数并返回单位矩阵的函数订单nx n。

--hints--

idMatrix应该是一个功能。

assert(typeof idMatrix == 'function');

idMatrix(1)应该返回一个数组。

assert(Array.isArray(idMatrix(1)));

idMatrix(1)应返回"+JSON.stringify(results[0])+"

assert.deepEqual(idMatrix(1), results[0]);

idMatrix(2)应返回"+JSON.stringify(results[1])+"

assert.deepEqual(idMatrix(2), results[1]);

idMatrix(3)应返回"+JSON.stringify(results[2])+"

assert.deepEqual(idMatrix(3), results[2]);

idMatrix(4)应返回"+JSON.stringify(results[3])+"

assert.deepEqual(idMatrix(4), results[3]);

--seed--

--after-user-code--

let results=[[ [ 1 ] ],
[ [ 1, 0 ], [ 0, 1 ] ],
[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ],
[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]]

--seed-contents--

function idMatrix(n) {

}

--solutions--

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;
        })
    });
}