Skip to content

Instantly share code, notes, and snippets.

@kctrlv
Last active November 28, 2016 06:32
Show Gist options
  • Save kctrlv/ccf46069560c5ed4f59a9f8a6796f10d to your computer and use it in GitHub Desktop.
Save kctrlv/ccf46069560c5ed4f59a9f8a6796f10d to your computer and use it in GitHub Desktop.

##Leap

My code

  • Responder #1 - This responder used a class with a constructor. It seems this can be done in JS many different ways.

  • Responder #2 - This responder solved the problem with a single return statement. Returns true if it's divisible by 400 OR (it's divisible by 4 AND not 100). I like this solution better than mine.

  • Responder #3 - This responder had the same approach as #2. A single return statement that returns true if evenly divisibly by (400 OR (4 AND NOT 100)).

  • Responder #4 - This responder also had the same approach as #2 and #3. A single eloquent return statement that checks if it's a leap year in one line.

  • Responder #5 - The final responder had a similar approach to the one I took, although it is less elegant. The first check for it being divisible by 100 is redundant because it has to be if it's divisible by 400.

##Hamming My code

  • Responder #1 - This responder used let, it was my first time seeing it in javascript. Otherwise, the methodology was the same as mine - throw an Error if the two lengths are not equal, otherwise increment the distance by one for each indexed place that the two strings are not equal to each other in that place.

  • Responder #2 - Again, very similar to my approach. Throw new Error if lengths are unequal, otherwise iterate through the length of one of the strings, increment difference, and return it at the end.

  • Responder #3 - Very similar to my answer, except there was an extra step added for splitting each string into an array first. This is unnecessary, as the length and the position can be checked similarly for a string which the argument comes in as.

  • Responder #4 - Consice answer that is very similar to mine. Throws error if the lengths are not the same, initializes the distance to 0, but then the responder uses a function in a forEach. It's a little less clear to me what's going on.

  • Responder #5 - Right away, throws error if the lengths are not the same. This responder sets a variable len to the length of the first string instead of just calling .length in the for loop.

##RNA Transcription My code

  • Responder #1 - This response takes the approach of initialising an empty string, iterating through an array of the split string, and appending an appropriate translated letter ot the string. I feel that it doesn't do as good a job at breaking up responsibility as my solution.

  • Responder #2 - A single-line solution! Just calls multiple replaces on the string, but not sure why the responder transforms it all to uppercase in the end as opposed to replacing the letters with upper-cased letters from the start. There must be a reason.

  • Responder #3 - Utilizes switch/case as well, but it is very wordy and the switch statement doesn't return but uses replaceAt. Less concise.

  • Responder #4 - Similar to the first responder, the solution involves initiliazing an empty string, and then a phrase I'm not sure I know how it works (let x of input). In the end, the finished 'result' string is returned.

  • Responder #5 - This is a really nice way of seperating out the transcription translation to a seperate object. The rest is similar to my solution - the responder users map on the split string, and calls a function that checks the object's attribute, followed by join(''). Very similar approach to my solution with split('').map(translationFunction).join('')

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