Skip to content

Instantly share code, notes, and snippets.

@s-espinosa
Last active June 24, 2016 21:58
Show Gist options
  • Save s-espinosa/f6e7d10a8d1d9500887dd5e64ad4adf4 to your computer and use it in GitHub Desktop.
Save s-espinosa/f6e7d10a8d1d9500887dd5e64ad4adf4 to your computer and use it in GitHub Desktop.
Review and Comparison of JS Exercisms

Leap

My code: here

Alternative solutions seemed to follow one of three approaches:

Approach #1 (here, here, here, and here) - This approach, the most popular based on my small sample, strings the test conditions together into a single line of code that inherently returns true or false when called. It's an elegant solution, but maybe not the easiest to maintain? I understood it quickly having just gone through the problem, but I'm not positive I'd find it as easy to parse if I were to come back to it a year from now. The logic doesn't necessarily seem to map clearly to the problem at hand.

Approach #2 (here, here, and here) - This approach is closest to my solution, though I like both of these implementations better. I couldn't quite find the shortest way to write that first condition, and both of these examples do. This approach requires more lines of code, and explicit returns for each case, but it seems easier to follow without much prep.

Other Approaches (here, and here) - One of these approaches takes the modulo operator out of the main logic, which doesn't seem to actually simplify anything. The other nests the if statements, which separates earlier statements from their return values making it somewhat harder to parse.

Hamming

My code: here

Responder #1 - #3 (here, here, here) - These three responses were nearly identical to each other and to my response. It seems like a straighforward implementation given the task at hand.

Responder #4 (here) - This differs in that the counter is defined prior to the error check. Putting it after the check (as in 1-3) seems to avoid that step altogether if it's not needed. I appreciate that they named the counter "dist" to reflect the language used in the problem description.

Responder #5 (here) - I agree with the existing comment about the else statement in this example (doesn't seem necessary), though I'm a little surprised that returning diff inside the for loop works. I would expect this to return the difference each time through the loop.

Responder #6 (here) - This seems a little too clever. The reduce seems unnecessary, as does the split. It's not immediately clear what's happening from a quick look at the code.

RNA Transcription

My code: here

Responder #1 (here) - I'm intrigued by the use of .map. It requires .split, which isn't the biggest deal, but I can't tell if the idea of mapping one array of things to another gets to the heart of this problem more directly.

Responder #2 (here) - Agree with the comment that line 7 could be simplified. Otherwise this is very close to my solution.

Responder #3 (here) - I don't like using map to name the lookup table. This is a different (possibly cleaner) implementation than #1, but it leaves me with the same question: does it make more sense to think of this as replacement of characters in a string or as using one string to generate another. Might be a minor difference, but I wonder if one approach is more easily understood.

Responder #4 (here) - Like the spacing for the dictionary. I forget exactly defining a function on this as part of the original constructor declaration impacts the object. I thought there was a reason I didn't do that, but now that I see this implementation I'm not as sure. Still trying to think of a good name for the _dictionary/lookup hash.

Responder #5 (here) - The else ifs in this example seem unnecessary given responses 1-4. Spacing also throws me off. Otherwise this seems to get the job done.

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