Created
December 5, 2010 18:32
-
-
Save gilesbowkett/729329 to your computer and use it in GitHub Desktop.
I have no idea what this field is for
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
# my first serious ruby question in like forever: | |
class Array | |
def token_diff(other) | |
memo = 0 | |
self.each_with_index do |element, index| | |
memo += 1 if other[index] != element | |
end | |
return memo | |
end | |
end | |
# this works only for the naïvest of cases: | |
# >> [:a, :b, :c].token_diff([:a, :b, :c]) | |
# => 0 | |
# >> [:a, :b, :c].token_diff([:a, :b]) | |
# => 1 | |
# >> [:a, :b, :c].token_diff([:a]) | |
# => 2 | |
# and fails... | |
# >> [:a, :b].token_diff([:a, :b, :c]) | |
# => 0 | |
# I know there are better, more elegant ways to do this, but I'm stumped. halp!!!1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand
Both a and b have 2 elements; the first element of each is
:a
.