Skip to content

Instantly share code, notes, and snippets.

@rossedfort
Last active February 7, 2016 17:55
Show Gist options
  • Save rossedfort/7614482867f8e8696665 to your computer and use it in GitHub Desktop.
Save rossedfort/7614482867f8e8696665 to your computer and use it in GitHub Desktop.
Javascript Exercism Comparisons

Leap

my code

  • responder 1 - This person took a very similar approach that I did, except the logic was exactly the opposite. Instead of checking if the year was evenly divisible by 4, they checked if it wasn't.
  • responder 2 - Ryan's approach is very explicit in that it has different conditions for each case. To me, it reads easier event though it is slightly longer.
  • responder 3 - Amber's approach is extremely simplistic. She takes advantage of the fact that conditionals return a true or false value inherently, thus removing the need to explicitly return true or false.
  • responder 4 - This is another example of an easily readable solution even though it is slightly more verbose.
  • responder 5 - This user broke out the main logic of the program into a separate function. To me this seems slightly unnecessary due to the fact that the logic is a simple modulo calculation.

Hamming

my code

  • responder 1 - Adam's solution is very simple and easy to understand. A simple counter that starts at 0 is used to track the differences of the two strings.
  • responder 2 - This user makes really good use of the reduce enumerable. It seems slightly more difficult to read than a for loop, but the .reduce seems more well suited for the problem.
  • responder 3 - This user also makes great use of the reduce enumberable. His variable naming is slightly more confusing though. In the comment section, someone recommended splitting both strings into arrays, or neither, but I'm not quite sure why it matters. Only one is necessary in order to use the enumerable.
  • responder 4 - This user makes great use of the try...catch statement. I wasn't aware this existed until seeing it, and once I did some research I think it is a good approach to this problem, given that an error should be thrown when the strings aren't the same size.
  • responder 5 - This user has an extra condition to check if the input strings are the same. If they are, it returns 0. If not, the program goes into the logic to check the difference. I think this approach is prbably slightly faster, because if you have two identical really long strings, it can return 0 before looping over the enire string.

RNA Transcription

my code

  • responder 1 - Adam makes great use of the forEach method which given his approach works really well. I like how he sets a base empty string and concatinates the RNA equivalent, eliminating the need for .map
  • responder 2 - Using a combination of split join and map, this user is able to accomplish his solution in very few lines of code. Also, instead of assigning new variables to the enumerable, he simply returns it.
  • responder 3 - Amber's solution is quite similar to mine. She uses .map to fetch the appropriate nucleotide equivalent from a key hash
  • responder 4 - This user took a very similar approach to Adam in that he set up a blank string and added the transcribed nucleotide to it, although he used a for loop instead of forEach.
  • responder 5 - Robbie makes great use of a separate function which holds a switch statement. This is the first time I had seen it, and I think it is a great solution to this problem
@rrgayhart
Copy link

👍

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