freeCodeCamp/curriculum/challenges/japanese/10-coding-interview-prep/rosetta-code/dot-product.md

1.5 KiB

id title challengeType forumTopicId dashedName
5a23c84252665b21eecc7e1e ドット積 1 302251 dot-product

--description--

Create a function, to compute the dot product, also known as the scalar product of two vectors.

--hints--

dotProduct という関数です。

assert(typeof dotProduct == 'function');

dotProduct([1, 3, -5], [4, -2, -1]) は数字を返します。

assert(typeof dotProduct([1, 3, -5], [4, -2, -1]) == 'number');

dotProduct([1, 3, -5], [4, -2, -1])3 を返します。

assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3);

dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])130 を返します。

assert.equal(dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), 130);

dotProduct([5, 4, 3, 2], [7, 8, 9, 6])106 を返します。

assert.equal(dotProduct([5, 4, 3, 2], [7, 8, 9, 6]), 106);

dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6])-36 を返します。

assert.equal(dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6]), -36);

dotProduct([17, 27, 34, 43, 15], [62, 73, 48, 95, 110])10392 を返します。

assert.equal(dotProduct([17, 27, 34, 43, 15], [62, 73, 48, 95, 110]), 10392);

--seed--

--seed-contents--

function dotProduct(ary1, ary2) {

}

--solutions--

function dotProduct(ary1, ary2) {
  var dotprod = 0;
  for (var i = 0; i < ary1.length; i++) dotprod += ary1[i] * ary2[i];
  return dotprod;
}