Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
11
Task/Dot-product/JavaScript/dot-product-1.js
Normal file
11
Task/Dot-product/JavaScript/dot-product-1.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function dot_product(ary1, ary2) {
|
||||
if (ary1.length != ary2.length)
|
||||
throw "can't find dot product: arrays have different lengths";
|
||||
var dotprod = 0;
|
||||
for (var i = 0; i < ary1.length; i++)
|
||||
dotprod += ary1[i] * ary2[i];
|
||||
return dotprod;
|
||||
}
|
||||
|
||||
print(dot_product([1,3,-5],[4,-2,-1])); // ==> 3
|
||||
print(dot_product([1,3,-5],[4,-2,-1,0])); // ==> exception
|
||||
Loading…
Add table
Add a link
Reference in a new issue