Skip to content

Instantly share code, notes, and snippets.

@patwey
Last active February 26, 2016 17:29
Show Gist options
  • Save patwey/db27840c0217aef5a8a5 to your computer and use it in GitHub Desktop.
Save patwey/db27840c0217aef5a8a5 to your computer and use it in GitHub Desktop.

Javascript Exercisms

Disclaimer: All of my code was written before I understood modules.

Leap

My Code

Responder #1

  • I like how their code is organized, with the isLeap method on the prototype. I don't like that their method is one line, I think it could be clearer if it were split up.

Responder #2

  • I really like this solution. Abstracting the logic into english-like variables makes the longer return at the bottom much more readable

Responder #3

  • This solution could be simplified - the explicit returns of true or false could be refactored to just returning the conditionals themselves (since they'll resolve ot true or false). There also seems to be some inconsistent indentation.

Responder #4

  • I like that this code establishes that 2015 is not a leap year.

Responder #5

  • Again, this code could be refactored to remove the returns of true / false. I find that the unfamiliar formatting makes it slightly harder to follow.

Hamming

My Code

Responder #1

  • I like that this person chose more descriptive variable names than my "a" and "b". I'm not sure if I feel like it was necessary to abstract chain1.length into a variable above the for loop, but I appreciate the thought.

Responder #2

  • This solution uses a while loop. It looks much cleaner, but I'm not sure that it's as clear how long the loop will run for. I personally like being able to see a more explicit condition.

Responder #3

  • This solution is so similiar to mine! I don't think that the strings need to be split into arrays, since their chars can be accessed like an array already. I also think we would both benefit from more descriptive variable names.

Responder #4

  • I like this solution a lot. I like their choice of variable names over mine, though I'm curious about whether count or distance provides more information in this context. count is more familiar and makes it easier to immediately recognize the purpose of the variable, but I wonder if distance is more tailored to the problem at hand. Then again, maybe it's not necessary for the person writing/reading this solution to have that information...

Responder #5

  • I like that this solution broke the logic into two functions. This approach seems much more reusable than mine. I also like that this person threw an actual error instead of a string, nice goin'!

Rna Transcription

My Code

Responder #1

  • This solution breaks the DNA strand into an array, transcribes it to RNA, and then joins it back into a string. I like this approach, and it makes more sense to me than adding the transcribed RNA to a new string.

Responder #2

  • This person chose to do the transcription using a case statement instead of referencing an object. I don't like this approach as much, since there is more repetition and the code is less reusable.

Responder #3

  • This approach uses str.replace, and seems pretty elegant and straightforward. I'm a fan. Side note: I don't know why there is a 1 on line 16. At first I thought it was part of the function so that it returned true, but now I see that it's not.

Responder #4

  • This person's solution is pretty similar to mine, with the transcribed RNA being added on to a new string. I do think they could've chosen a better name than table to represent the RNA counterparts of DNA.

Responder #5

  • Like the comment mentions, the logic here could be handled better with a switch statement. I also think that it would be a better solution to break out the RNA counterparts into an object like some of the other solutions... It's easier to read and removes some of the repetition of this approach.
@rrgayhart
Copy link

Good work 👍

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