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.2 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
594810f028c0303b75339ad2 矢量交叉产品 5 vector-cross-product

--description--

矢量被定义为具有三个维度由三个数字的有序集合表示XYZ

任务:

 Write a function that takes two vectors (arrays) as input and computes their cross product. 

您的函数应在无效输入(即不同长度的向量)上返回null

--hints--

dotProduct必须是一个函数

assert.equal(typeof crossProduct, 'function');

dotProduct必须返回null

assert.equal(crossProduct(), null);

crossProduct[1,2,3][4,5,6])必须返回[-3,6-3]。

assert.deepEqual(res12, exp12);

--seed--

--after-user-code--

const tv1 = [1, 2, 3];
const tv2 = [4, 5, 6];
const res12 = crossProduct(tv1, tv2);
const exp12 = [-3, 6, -3];

--seed-contents--

function crossProduct(a, b) {

}

--solutions--

function crossProduct(a, b) {
  if (!a || !b) {
    return null;
  }

  // Check lengths
  if (a.length !== 3 || b.length !== 3) {
    return null;
  }

  return [
    (a[1] * b[2]) - (a[2] * b[1]),
    (a[2] * b[0]) - (a[0] * b[2]),
    (a[0] * b[1]) - (a[1] * b[0])
  ];
}