Created
January 23, 2019 10:42
-
-
Save troessner/4421add4c2a9f2a39f6beb17f579e05c to your computer and use it in GitHub Desktop.
sim function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# That's a lambda in case you haven't seen this yet: https://blog.honeybadger.io/using-lambdas-in-ruby/ | |
# def sim()... would also work but without an object an functional style (using a lambda) is more idiomatic. | |
sim ->(matrix, base_line, compare_to) do | |
# -> TODO | |
end | |
matrix = Matrix[ # See https://ruby-doc.org/stdlib-2.5.1/libdoc/matrix/rdoc/Matrix.html | |
[1, nil, 3, nil, nil, 5, nil, nil, 5, nil, 4 nil], # first row | |
[] # second row and so on | |
] | |
assert_equal -0.18, sim(matrix,1 ,2) | |
assert_equal -0.59, sim(matrix,1 ,6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment