Skip to content

Instantly share code, notes, and snippets.

@zackforbing
Created October 11, 2016 00:25
Show Gist options
  • Save zackforbing/68eb3eeaac487157f99e3043ed022aa1 to your computer and use it in GitHub Desktop.
Save zackforbing/68eb3eeaac487157f99e3043ed022aa1 to your computer and use it in GitHub Desktop.
Hamming Exercism

##Hamming My code: here

I didn't have any responses to this. Now we are getting to the juice. this problem took me a minute to think about how to build, but comparing two strings isn't too difficult. I initially thought I could use indexOf to compare the chars, but realized I was looking at it backwards.

  • Option #1 (here) - about the only difference other than variable names in this coder's solution was that they just grabbed index [i] of each string to compare. slightly more compact, slightly less verbose.

  • Option #2 (here) - this coder opted for a shorter ternary, but also included the longer form in commented out code. it's clever, but it also explains to you what is going on. although I think I would have just used the longer code. this amount of verbosity feels like overkill.

  • Option #3 (here) - I like the error call coming last. it should be the least used operation, so that seems like its logical place. however, I wonder how both this solution and mine are working, when I am using i = 0 and i <= first.length and they are also using i = 0, but then using i < strand1.length? it also occurred to me while looking at these solutions that I could have implemented this using a forEach loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment