Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
13
Task/Dot-product/CoffeeScript/dot-product.coffee
Normal file
13
Task/Dot-product/CoffeeScript/dot-product.coffee
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
dot_product = (ary1, ary2) ->
|
||||
if ary1.length != ary2.length
|
||||
throw "can't find dot product: arrays have different lengths"
|
||||
dotprod = 0
|
||||
for v, i in ary1
|
||||
dotprod += v * ary2[i]
|
||||
dotprod
|
||||
|
||||
console.log dot_product([ 1, 3, -5 ], [ 4, -2, -1 ]) # 3
|
||||
try
|
||||
console.log dot_product([ 1, 3, -5 ], [ 4, -2, -1, 0 ]) # exception
|
||||
catch e
|
||||
console.log e
|
||||
Loading…
Add table
Add a link
Reference in a new issue