Skip to content

Instantly share code, notes, and snippets.

@ryanflach
Forked from anonymous/exercism.markdown
Last active October 12, 2016 14:44
Show Gist options
  • Save ryanflach/cc7d144b0fba9844987fcca1c503122b to your computer and use it in GitHub Desktop.
Save ryanflach/cc7d144b0fba9844987fcca1c503122b to your computer and use it in GitHub Desktop.

Leap

My code: here

  • Responder #1 (here) - This individual took a similar approach, though they did not utilize a ternary. Additionally, they used an interesting check with the modulo to ensure that the remainder for the year / 100 was greater than 0, and not equal to 0. I assume this was done in place of ensuring that it was not cleanly divisible by 100, but I found it to be a less readable implementation.
  • Responder #2 (here) - This individual's approach was verbose with regard to usage of return statements for true or false, but, as a result, it was easy to follow their thought process. I was intrigued to see usage of an if statement after an else if. It indicated a level of flexibility within JavaScript syntax that I wouldn't have expected.
  • Responder #3 (here) - This individual utilized three single-line if statements that were very clear to read. Although more verbose than my own solution, I think it may have been more readable. They did have some unnecessary checks, however (i.e. first checking if year % 4 !== 0), that were already covered in their other conditionals.
  • Responder #4 (here) - This individual's approach was the most different from my own thus far. Their syntax for defining the class and isLeap method were defined with explicit constructor and without prototype. Additionally, they used constants within the isLeap method to improve readability, ultimately using only one return statement. Although more verbose than my own solution, I found it very readable and clearly written.
  • Responder #5 (here) - This was another solution more similar to the others and my own. Like #3, this individual used single-line if statements, but then used a final check to return if the year was evenly divisible by 0. I found this solution to be a readable and fairly clear implementation.

Hamming

My code: here

  • Responder #1 (here) - This solution differed from mine in both order of operations and by using a for loop that decremented, rather than incrementing. Outside of these differences the approach was very similar. I found their naming of local variables to be slightly clearer than my own, particularly with regard to the arguments passed to the compute method.
  • Responder #2 (here) - This solution was nearly identical to my own: it first checked for an error and then proceeded with the for loop and return of the difference. It differed slightly by not defining the local diff variable (count in my own implementation) until necessary.
  • Responder #3 (here) - Similar to their approach in the Leap exercise, this individual again used ES6 syntax in their class construction. They continued use of constants, and in place of a for loop utilized .filter() to generate an array that they then returned the length of. Additionally, they used syntax that I had not previously seen (const strandA = [...a];) that acted as a shortcut for a.split('');. Although this was a very clean and clever approach, I didn't find it as readable as their solution for Leap.
  • Responder #4 (here) - This solution was more similar to my own, and very similar to responder #2.
  • Responder #5 (here) - This solution used .reduce() and some ES6 syntax. By returning the result of the reduce function directly it allowed them to reduce one or two lines of code, but this was made somewhat irrelevant by the if/else in the reduce block. I liked the use of reduce, but, without the use of local variables to assist in naming, found this implementation to be slightly less readable than the others.

RNA Transcription

My code: here

  • Responder #1 (here) - This solution was very similar to my own, but they used ES6 syntax for a slightly cleaner implementation. Additionally, they used a constant to define their hash table, which I believe to be a better implementation than my own use of var for that object.
  • Responder #2 (here) - This individual's approach was very similar to the responder #1's, only with the use of ES5 syntax. They also used a constant to store the translation object.
  • Responder #3 (here) - This solution defined the translation object within the toRna method and then called it on the passed in argument like a method. This implementation was very interesting to me, as it appeared to be utilizing regex to control against characters not found in their translation object. Although unnecessary in this context, this was the most dynamic solution I had seen this far.
  • Responder #4 (here) - The ES6 champion is back with another interesting solution. In this implementation they set a constant that is new Map that sets each translation. In their return they .map and .reduce to return the ultimate translation. I found this solution to be incredibly unreadable, and ultimately more verbose than other solutions. They seem to very much know what they are doing, but are letting their own intelligence get in the way of writing readable, simple solutions.
  • Responder #5 (here) - This individual's solution was very easy to follow, due to the use of comments and clear variable names, but ultimately solved many problems they were not asked to. Initially, they check to ensure that an argument is passed, and then they validate a valid string with regex. Around halfway through their method they begin to solve the problem at hand. Although readable, I didn't care for this particular implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment