Skip to content

Instantly share code, notes, and snippets.

@PenneyGadget
Last active March 19, 2016 21:57
Show Gist options
  • Save PenneyGadget/a16fe3e5516a67bf04fa to your computer and use it in GitHub Desktop.
Save PenneyGadget/a16fe3e5516a67bf04fa to your computer and use it in GitHub Desktop.
A comparison of my javascript exercism solutions with 5 other peoples solutions

##Leap My code

  • Solution #1 - This is Jamie's solution which I found super interesting in terms of readability. Instead of just writing code to say a year is or is not a leap year, he's defined what the conditions are with descriptive names so the code reads in a very English way. I think it's cool.
  • Solution #2 - I'm really confused by the variable assignments in this.. Unless I'm missing something, the way century is calculated it will ALWAYS return true for century % 100 === 0, so it's a useless check. The else { return false } is also unnecessary.
  • Solution #3 - This is some interesting and bizarre syntax I've never seen before. It's very short and concise, but in a way that makes it less readable. This could very likely just be because I know next to nothing about what "good" javascript looks like, but it seems overly clever and stripped down.
  • Solution #4 - Because this person created their own isDivisibleBy function I was thinking "Oh, poor person doesn't know about modulos". But then I noticed that they used a modulo in their custom method! Weird. Not sure why they decided to do that. I also don't understand why they are using the underscore before everything - I had to look this up, found it's a why to indicated private methods but it doesn't acutally make them private and is not recommended. Overall I just find this bad code.
  • Solution #5 - This is an interesting (yet rather verbose) approach. I don't think they understand prototype however, because (if I understand it) you do not have to reiterate var input = this.input; in the isLeap function - it inherits that from the original Year function.

##Hamming My code

  • Solution #1 - Well I learn a lot by looking at this, because I don't know how to use map and reduce very well in javascript yet. She has chosen to use those methods instead of creating a counter which seems to be what most people do. It's pretty cool, though this makes it more complicated to read and (I think) creates extra lines of code because you have to do the split (unnecessary if you just iterate through with a for loop)
  • Solution #2 - I like the way the counter is incremented inside the for loop with one line syntax by using &&. This gets rid of some lines of code that I needed because I put an if statement inside my loop.
  • Solution #3 - This is cool! I like the use of the reverse counter and the concise while loop.
  • Solution #4 - This is nice, I like the additional distance function for readability, though splitting the strings is not necessary because the for loop will iterate through each index of the string. But it's something I'm seeing that Ruby people want to do ;)
  • Solution #5 - This is a different way to use a for loop that I haven't seen before. I thought you always had to set the variable, give it a stopping point, and give it a counter, but here i somehow still knows to increment itself up? Also you can make classes in javascript? I didn't know that.. so many questions and things to learn!!

##Rna Transcription My code

  • Solution #1 - I really like this solution, it's so clean and concise. Go Beth!! My solution felt very amateur and clunky to me, and this eliminates that by creating a "rna Dictionary" at the beginning and then just mapping through. Wish I would have thought of that approach.
  • Solution #2 - Toni had the same approach in making a "conversions" object. She doesn't need to split the strings because she's using a for loop instead of mapping. Really nice.
  • Solution #3 - Wow, this is super refactored. I'm not sure if I like it better than a slightly more verbose/descriptive solution, but it's really interesting. I'm still a little confused by when and where return needs to go - this solution it's called 3 times.. I'm curious if that's actually necessary for it to work?
  • Solution #4 - I tried to use a switch/case statement inside my loop like this person did, but couldn't get it to work for the final test for some reason. This is long and repetitive (mostly because of all the breaks, but I do really like case statements because of how easily they read - very English-like.
  • Solution #5 - This solution is much like the first two, but I like the feedback comment that was left for her - the guy explains the difference between forEach and map in a way I found really helpful.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment