Skip to content

Instantly share code, notes, and snippets.

@lsaville
Forked from neight-allen/exercism_submission.md
Last active January 24, 2018 18:15
Show Gist options
  • Save lsaville/861c956749c7229be8827f068333c7ed to your computer and use it in GitHub Desktop.
Save lsaville/861c956749c7229be8827f068333c7ed 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

hello-world

My code: link to submission

  • Other Solution #1 (link to submission) - The first striking thing about this example is its uitilization of 5-space tabs! It feels like it has been a very long time since I've seen such large indentions. The tatic here is to prep a variable called name with the input, if there is any (if there's not it will be 'World') and then returning the full phrase. The person is using backticks with what seems to be string interpolation like `Here is some ${var}`, which is something which I though javascript wasn't capable of. It turns out that these are 'template literals' of es6 and they feel much more like string interpolation as in ruby.

  • Other Solution #2 (link to submission) - This solution uses 5-space tabs AND double spacing. I had assumed from ruby that an empty string would be truthy where in javascript an empty string is interpreted as false. This solution also puts the 'guard' case (that might not be the right terminology, for it I mean the part of an if/else that is returned if nothing more interesting was provided) up top with !input, which I've often found baffling in terms of trying to figure out what !anything might mean in a given context. I suppose in my mind I associate the dynamic part of the code to be more interesting and thus deserving of coming before the 'default' phrase.

  • Other Solution #3 (link to submission) - The solution utilizes an empty string being false with an 'early' return if the input happens to be truthy. If the early return doesn't happen, the stock phrase is returned. This was also one of the examples in which the user did not delete the comments guiding where the code should go.

  • Other Solution #4 (link to submission) - This is somewhat the opposite of Other Solution #1 in that it assigns a variable for part of the chunk of the phrase except that, that chunk is the 'Hello, ' part instead of the dynamic portion.

  • Other Solution #5 (link to submission) - This solution was one of the more interesting ones. In it the person is using backticks with what seems to be string interpolation like `Here is some ${var}`, which is something which I though javascript wasn't capable of. It turns out that these are 'template literals' of es6 and they feel much more like string interpolation as in ruby. Additionally, as in some of the other solutions I've been looking at this one utilizes || and the false-ness of an empty string. I had assumed from ruby that an empty string would be truthy where in javascript an empty string is interpreted as false. This example seems the cleanest and is my favorite.

Leap

My code: link to submission

  • Other Solution #1 (link to submission) - This example uses es6 class notation with the constructor function (something akin to intialize in ruby). It also does the module export at the same time. This style of defining the class is more similar to ruby then the other way of doing it explicitly with setting up the object and then adding the function isLeap() to the prototype (both under the hood are doing the same thing). I notice that this person has also assigned this.year to the variable year and then asks some questions about the year. I suppose this is preferable to stating this.year over and over again. To my eye the return statement is difficult to read and would take some time to pluck apart.

  • Other Solution #2 (link to submission) - In this solution the author used a similar && || statement as the last, the one which I find slightly baffling that needs intense study (I suppose it should be noted that my solution would likely need some study to figure out exactly what its saying (perhaps the nature of a leap year?)). The author made an attempt to shorten the line by breaking it on the ampersand. The author also used value as the parameter placeholder instead of year which I was at first miffed by, but could be arguably more correct in the context of the 'class' Year... Year having a value as opposed to Year, year.

  • Other Solution #3 (link to submission) - I would guess that the author of this double-spaced/5-space tabbed solution is this same as solution #2 for hello-world. The author also breaks the if/else statement in what I would consider a non-idiomatic way (somewhat surprising that I've already got opinions about js style... perhaps those hours doing code academy were not lost?). The logic is the same as the previous two solutions but more verbose in the fact that the author explicitly returns true or false which is unecessary.

  • Other Solution #4 (link to submission) - This solution uses a nested if statement which would probably be better refactored into something like the && || solutions from above (via Jeff's lesson about refactoring nested ifs). I think we're meant to frown upon comments left in the code, but the comments are clearly composed and make sense.

  • Other Solution #5 (link to submission) - This solution is even more nested than #4 and features comments. I think again that we would want to refactor this so that it isn't nested.

Hamming

My code: link to submission

  • Other Solution #1 (link to submission) - This solution uses an if statement with a for loop inside of it with an if inside of that. I've definitely been conditioned to be uncomfortable with multiple layers of nesting. This user also throws a new Error instead of just throwing a string like I did. After a look into the differences between the methods, new Error is a much better option because it provides more context without having to click on the unnesting arrow in the console. Additionally this solution chooses to use length as the counter variable name, which is inconsistent with what the counting variable represents.

  • Other Solution #2 (link to submission) - Another example of 5-space tabs. The user has some comments referring to 'body', I'm not sure what that is signifying. The user shortens the variable names as a rule. The solution also makes use of a new Error as I should have done.

  • Other Solution #3 (link to submission) - This solution makes use of an enumerable called forEach and takes extra steps to allow its usage, as in lines 7 and 8 where the user splits each arugment in preparation. This seems unecessary. The solution also names the counting variable as match, which is the opposite what is being counted.

  • Other Solution #4 (link to submission) - This solution uses only x and y for variables. It's a small bit of code and you can follow but in a larger scenario this could hinder the understanding of a future developer. Line 7 catches my eye in that it is a one line if statement that omits the use of {},, which apparently is allowable, if not desireable. This is an aspect of javascript that is mystifying, it seems so picky about syntax sometimes and its difficult to know which thing is really required at first. Surely this is an aspect of learning any language.

  • Other Solution #5 (link to submission) - This solution has everything nested in an if statement. If the strands are equal, it does the primary action of the function, otherwise it throws an error. It makes me wonder about what is the canonical manner of setting up a function with error handling. In my mind the main part of the function is to do it's prinicipal job, namely, count the differences between strands. The way this solution is setup the emphasis is removed from that prinicipal job in the way it feels. A beneficial part of doing these exercisms is seeing that there are indeed many ways to organize a bit of code. We've definitely been seeing that a bit throughout our time at turing, but it seems highlighted in this context where we look at 5 different ways from largely disparate individuals (aka not influenced by the general turing philosophy). Additionally we can know that the solutions each work, and with my untrained js eye I would have expected many of them not to.

Rna Transcription

My code: link to submission

  • Other Solution #1 (link to submission) - I like how this solution has the transcribing piece broken out into two functions. The splitting seems unecessary (and is only done to use the enumerable on an array). Having a full function with a case statement also seems a little heavy when you could utilize a hash.

  • Other Solution #2 (link to submission) - I like where this solution is heading using a variable to store the map. It might be slightly less performant in that it conjures an array and then simply joins it in the end. I think the array need not ever exist. This solution makes me wonder if I put my rnaCipher in the right place, within the contructor, or whether it is better for it to be inside the toRna() function as a local variable.

  • Other Solution #3 (link to submission) - This solution works directly on an empty string, which I like, but is lacking the dictionary for translation and thus has a lot of repitition within the for loop regarding newSequence += whatever letter is in the part of the if/else. The solution has some white space dividing the main parts of the function and its very easy for me to see those different parts as a result. I have been smashing everything together and perhaps am suffering a lack of clarity for it. I'd be curious what the idiomatic approach might be; if the clarifying spaces are encouraged or not.

  • Other Solution #4 (link to submission) - This solution adds bonus error handling! Lines 9-13 exhibit some syntax I've never seen before and upon a cursory search cannot find in google... It seems to be some sort of switch statement shorthand or stacked ternaryies??? Upon closer inspection the block is indeed a series of chained ternaries. The author uses this to squeeze out a false if the letter doesn't match any of the values and uses this false to trigger the error handling and spits out a dynamic string specifying the letter and the index that did not match anything in the if/else.

  • Other Solution #5 (link to submission) - This solution utilizes a switch statement and is a little bit chunkier for lack of +=. We basically share the same method of acheiving the end goal with the exception of the swith statement.

Bob

My code: link to submission

  • Other Solution #1 (link to submission) - I really like that this user has gone through 3 iterations, each a bit better than the last. I'd like to clean up my solution if I can get the time. The Solution has the 5-space tabs but the last submission limits the return values to the number of responses that 'Bob' is capable of. In my solution I repeat responses.

  • Other Solution #2 (link to submission) - This solution also has three iterations and has come out the cleaner for it. The solutions I've seen thus far have also avoided the use of regex, which seems like it's a little bit nicer (my solution has several examples of regex). The user went for three separate methods to process the type of request and used them as boolean conditions in the main if/else statement which seems to adhere closely to the spirit of the problem, namely, that Bob responds differently in the four cases: shouted, questioned, silent, or the catch all of any other. I clearly need to look into this technique I've been seeing of checking that the input == input.toUpperCase() && input != input.toLowerCase(). I'm becoming more unhappy with my solution as I go along :(

  • Other Solution #3 (link to submission) - This solution strong arms the problem with regex. The user is able to get all the returns down to the four and does so using some complicated regex techniques. I feel like regex gets a bad wrap, its definitely practically unreadable, but is also a powerful thing if you knew what you were doing. I suppose if regex were more widely known it would be more acceptable? Is it widely unknown? I can imagine it being difficult for a future developer to see a big chunk of regex (depending on that developer's regex experience) and know exactly what it is doing at first glance.

  • Other Solution #4 (link to submission) - The replace function used in this solution seems a bit over the top. I think it's just asking if the input contains numbers, but does so in the round about way of replacing them and asking about the length of the input. The other solutions I've reviewed seem to get around asking if the input is all numbers... Looking at the test suite again it seems like it is appropriate not to even think about whether it is only numbers and does fall under the all-else 'whatever.' category. Funn how looking at other solutions and yours and having a day between you and the problem can clarify what the problem was wanting and makes you wonder how you feel into some silly assumptions.

  • Other Solution #5 (link to submission) - This solution takes the input and strips out whitespace before asking any questions about the input at all. This accurately reflects the fact that whitespace being stripped from the input from the start takes care of the empty string problem and doesn't matter for the rest of the conditions. It seems strange to set the response to 'Whatever.' from the beginning, with a likelihood of it changing through the if/else to have it returned at the end. I don't know if thats just a feeling I have or whether it is more right not to use this technique.

@lsaville
Copy link
Author

lsaville commented Jan 23, 2017

@lsaville
Copy link
Author

screen shot 2017-01-22 at 4 09 37 pm

@lsaville
Copy link
Author

screen shot 2017-01-22 at 4 07 49 pm

@notmarkmiranda
Copy link

🔥

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