* 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>
1.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5a23c84252665b21eecc7e1e | Dot product | 5 | 302251 | dot-product |
--description--
Create a function, to compute the dot product, also known as the scalar product of two vectors.
--hints--
dotProduct
should be a function.
assert(typeof dotProduct == 'function');
dotProduct([1, 3, -5], [4, -2, -1])
should return a number.
assert(typeof dotProduct([1, 3, -5], [4, -2, -1]) == 'number');
dotProduct([1, 3, -5], [4, -2, -1])
should return 3
.
assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3);
dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
should return 130
.
assert.equal(dotProduct([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]), 130);
dotProduct([5, 4, 3, 2], [7, 8, 9, 6])
should return 106
.
assert.equal(dotProduct([5, 4, 3, 2], [7, 8, 9, 6]), 106);
dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6])
should return -36
.
assert.equal(dotProduct([-5, 4, -3, 2], [-7, -8, 9, -6]), -36);
dotProduct([17, 27, 34, 43, 15], [62, 73, 48, 95, 110])
should return 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;
}