Skip to content

Instantly share code, notes, and snippets.

@epintozzi
Forked from neight-allen/exercism_submission.md
Last active January 22, 2017 23:05
Show Gist options
  • Save epintozzi/da1a15ec854f978e60271031193975ce to your computer and use it in GitHub Desktop.
Save epintozzi/da1a15ec854f978e60271031193975ce to your computer and use it in GitHub Desktop.

Instructions

  • Fork this gist
  • Do 5 JavaScript exercisms
  • Compare your completed exercises to five answers that other folks got, writing a comment of what you saw when comparing the answer
  • Fill in the template below with your work

My Submission

Do 5 of these:

Hello World

My code: link to submission

  • Other Solution #1 (link to submission) - Though there aren't a lot of different ways I've seen people solve "Hello World", I thought it was an interesting approach to use ternaries instead of a traditional if/else statement here. Personally, I prefer the if/else because it's easier to read, but I was excited when I stumbled across this solution to see an alternate way of solving the problem that I hadn't thought of.

  • Other Solution #2 (link to submission) - Similar to the solution above, this also uses ternaries, however this submission does not trim the string first. I think either way is fine, just preference. Perhaps someone has a lot of white spaces in their name??

  • Other Solution #3 (link to submission) - I really like this solution. It uses pipes instead of a full if/else statement where the pipes are just choosing input or "world" to include in the string. Of all the solutions I've seen (including mine), I think I like this one best because it is short and sweet but also very easy to read and see what is happening.

  • Other Solution #4 (link to submission) - This solution stands out as incomplete to me since it only returns "hello world" and doesn't actually check for or return the input name. Though short and sweet, this probably does not pass all the tests.

  • Other Solution #5 (link to submission) - This submission is most similar to mine, however it does not check for if the input is undefined, only if it is an empty string. Though technically this would pass the supplied tests, I think a more robust solution would include the nil check. One thing to note for myself is to double check my use of brackets and semi colons on this solution. I believe I am missing some and just got lucky that the solution was simple enough for it to still pass.

Leap

My code: link to submission

  • Other Solution #1 (link to submission) - This solution feels both more complex and more simple than my own. More complex because of the multiple nested if statements, but more simple because I think (with the comments) it's a little clearer what each check is doing, whereas in my own solution, I have a single if/else but my if compares a couple things so could potentially be a little unclear to another developer at first.

  • Other Solution #2 (link to submission) - This solution uses ternaries which I find to be a little confusing. On one hand, this is a very simple, 1 line solution within the function, on the other, since it's all on one line, and the pieces aren't broken out at all, it isn't immediately clear what is happening.

  • Other Solution #3 (link to submission) - This submission has a lot of abstraction which is nice for clarity, but perhaps a bit too much. For my solution, I just set the result of the modulus equal to a variable rather than creating a function for the equation. I kind of like my way better because the variables then are one line for each, but are still named appropriate so when I do the comparisons, it's happening "in English" but the overall solution is a little shorter.

  • Other Solution #4 (link to submission) - Compared to my solution, there are a lot of else if lines here. Though in some ways it's more explicit because he is checking each condition on it's own, I think it's a little unnecessary and repetative and could be streamlined better.

  • Other Solution #5 (link to submission) - This solution is interesting to me both because of the nested if statement (which I find a little confusing) as well as setting an initial isLeap variable to a boolean rather than simply returning true or false at the end of the conditional statements. Though I would not solve it this way myself, it's certainly a helpful exercise to see the different options (like the isLeap variable) for future problems that may have similarities to this one.

Hamming

My code: link to submission

  • Other Solution #1 (link to submission) - This solution is very similar to mine, the one big difference that stands out is the the position counter variable is declared outside the loop. I'm unsure if that's problematic, but it appears this solution still works.

  • Other Solution #2 (link to submission) - Again, similar to mine, but I can't see where the error is being thrown. I'm guessing it was missed? I also like that this person uses distance ++ insted of += like I did. Though only a couple characters, I like that trick and want to try to remember it for future solutions that need a counter.

  • Other Solution #3 (link to submission) - This solution varies most from mine. I find the abstraction interesting. I think it can be helpful but personally would not have abstracted the count, only the error function. I also don't totally follow why split is being used. I believe you can just iterate through a string like an array. Additionally, I believe second.split is being run every time the loop goes through, thus would result in some performance decrease. I would think the splitting could happen outside of the loop (if it even needs to happen at all).

  • Other Solution #4 (link to submission) - This is another solution that splits the string first, which again, I don't think is necessary. Otherwise it is pretty similar to my own solution, though it throws the error at the end rather than at the beginning. I'm trying to think of a reason why one might be better than the other, but I think beginning or end, either is appropriate.

  • Other Solution #5 (link to submission) - This solution is very similar to mine as well, however after the length check, this person puts the counter loop in an else. Mine is not nested and the loop stands on its own after the length check, because, my understanding is that the error which stop running the program anyways, so nesting is not required, and thus is a little more readable.

RNA

My code: link to submission

  • Other Solution #1 (link to submission) - I like this solution because I was trying to figure out how to use map in my own and was not successful, so I'm happy to see it used. That said, I'm also happy with my solution because I transcribed directly to a string rather than first to an array and then joining that array.

  • Other Solution #2 (link to submission) - I think this solution is closest to my original approach of what I was trying to achieve though not specifically using map. This solution uses a dictionary to define the transcription key but also uses an array which is later joined. Since my solution did not require that extra step, I prefer my approach to keeping it as a string.

  • Other Solution #3 (link to submission) - This solution is interesting because it splits the string, pushes the transcribed characters to an array, and then joins. I feel like that could all be removed.

  • Other Solution #4 (link to submission) - This solution is interesting because it also defines a variable for character as an empty string. In my solution, I pull the character directly from the string whilst doing the transcription lookup. I think mine is readable enough that it's acceptable, but I do like the clarity that this person's solution brings.

  • Other Solution #5 (link to submission) - This solution solves with an if/else statement. I do think it brings a little immediate clarity to what's happening, but would also be much more difficult to scale. This is the first solution I've seen this way, and as with other problems, like seeing the variety of ways that I did not think of on my own to solve this.

Bob

My code: link to submission

  • Other Solution #1 (link to submission) - I really like this solution. I think it's abstracted well and very clearly. I understand exactly what's happening here. I'm also interested by the && input !== input.toLowerCase() part of the conditional in the isShouting method. I did a regex check to see if there were any alphabet characters. I'd love to try this instead of the regex check in my solution to see if it still works, because generally, I find regex expressions to be difficult to easily interpret with a quick review.

  • Other Solution #2 (link to submission) - This solution is interesting. Though it shares a lot of similarities with mine, I don't really understand the comparison check of && input[0] !== '4'. I believe this was written specifically to get one of the tests to pass and would potentially fail for an input that began with 4 but had other characters after it which would require either the "Whatever" or "Whoa chill out" responses.

  • Other Solution #3 (link to submission) - The use of switch is something I've not seen before so I like the exposure to this technique. The one thing that sticks out is that I believe this would actually fail for any input that is numbers and some other non-alpha character that isn't a comma (ex: "1- 2- 3"). Otherwise I think this is clear and well written.

  • Other Solution #4 (link to submission) - At first glance, this solution is unclear and dense because of all the nested if statements and comments. I also think the comparison check within in if statement could be clearer. I really can't tell if some of these would pass more rigorous testing.For example, on line 10, does this actually pass the test where the question mark is in the middle of the statement? I feel like it shouldn't.

  • Other Solution #5 (link to submission) - This submission is very similar to the first solution I reviewd but I like that the functions are defined before they are used later. Though I understand it still works correctly either way, in a very large program, I imagine it's helpful to see the functions defined before they are used since the English language naturally reads top to bottom.

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