Skip to content

Instantly share code, notes, and snippets.

@ksk5280
Last active May 8, 2016 17:29
Show Gist options
  • Save ksk5280/2c786b613ef027974c3e22e6b84cbb4a to your computer and use it in GitHub Desktop.
Save ksk5280/2c786b613ef027974c3e22e6b84cbb4a to your computer and use it in GitHub Desktop.
JavaScript exercism comparisons

##Bob My code: here

  • Responder #1 (here) - I really liked this response. Their line 9 was a very clever way of both determining if the input was in all caps and contained letters and not just numbers without using regex. Additionally they used the endsWith and trim functions which are great for determining if a sentence ends in a '?' or if it only contains whitespace. I changed my first submission after seeing this response because I was hoping to use functions like these, but didn't know them in JavaScript yet.

  • Responder #2 (here) - This person used regex to check for input with only whitespace, which I had done initially, but I prefer using 'trim()' to remove whitespace and then check the length. Their line 7 is really lengthy and it's not entirely clear what they are trying to accomplish just by looking at it.

  • Responder #3 (here) - This user wrote separate functions for the different tests. It makes it unnecessarily long and doesn't even make the code easier to read.

  • Responder #4 (here) - This responder used a lot of regex and other complicated code to write 130 lines for something that could be solved in 11 lines.

  • Responder #5 (here) - This solution is the same as the first one that I really liked. I also enjoyed the comment given by another: "This is so elegant I want to punch someone." Well said.

##Hamming My code: here

  • Responder #1 (here) - This answer more clearly names the counted variable 'hamming_distance' instead of 'count' as I did. They use 'throw new Error' instead of just 'throw' which I image might be better, although my solution still passed. They also immediately return the hamming distance if the strings are equal instead of going through the check. The rest of the code is similar to mine.

  • Responder #2 (here) - This solution is almost exactly the same as mine except for using 'throw new Error' instead of just 'throw'.

  • Responder #3 (here) - This responder put in a bunch of console.logs that probably should be taken out to make it easier to read. They split stringA and stringB in order to use forEach. It's similar to my answer, but I prefer the solution with the for loop that doesn't require splitting the strings.

  • Responder #4 (here) - This code is written to only pass the test, which is silly.

  • Responder #5 (here) - The solution creates a shortest string function. I'm not sure why that is necessary.

##RNA Transcription My code: here

  • Responder #1 (here) - This responder used a hash and map to create the RNA complement. This solution is far superior to mine.

  • Responder #2 (here) - This solution uses if else statements to find the complement. It adds an error if one of the letters is not valid, which I did not do.

  • Responder #3 (here) - This response uses switch as I did, but also uses map, which looks better than my solution.

  • Responder #4 (here) - This solution uses a bunch of nested ternaries which is interesting. The spacing and indentation is really bad and makes it harder to read.

  • Responder #5 (here) - This solution is similar to mine, but pushes the RNA strand into an array and then joins the array at the end instead of just adding strings together. I think my solution is slightly better.

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