Skip to content

Instantly share code, notes, and snippets.

@kjs222
Forked from anonymous/exercism.markdown
Last active October 8, 2016 23:18
Show Gist options
  • Select an option

  • Save kjs222/6a6eb8fee2ed930d2078c41344bef3cf to your computer and use it in GitHub Desktop.

Select an option

Save kjs222/6a6eb8fee2ed930d2078c41344bef3cf to your computer and use it in GitHub Desktop.

##Hello World My code: here

  • Responder #1 (here) - This person took the same approach but did not use the ternary operator. She used a single if statements to handle the situation where input was provided. There are two return statements - one on the if and one without a condition.

  • Responder #2 (here) - This person used a memoization type technique to handle whether input was provided or not. This is a valid approach, but is less intuitive (imo) than using a conditional.

  • Responder #3 (here) - I like the classical use of the if/else in this response. I think it's the most intuitive. I think the use of .length on the input is superfluous.

  • Responder #4 (here) - this person used es6 string interpolation sytnax, which I thought I tried and it didn't work... I assumed it was because the exercism didn't support es6. However, looks like I forgot to use the back ticks.

  • Responder #5 (here) - this person hardcoded the names to be passed in based on the tests, which works (and is pure TDD), but probably isn't the intent of the exercise :)

##Leap My code: here

  • Responder #1 (here) - This person handled all of the true scenarios is one compound condition. I feel like the use of three statements in the single if statement is not very readable, but I do like the idea of handling all trues in one place. Instead, I handled the "unique cases" in one section, and the standard cases in the other conditional.

  • Responder #2 (here) - This person used the most literal approach to all of the rules, including each one as its own conditional. I think this is very readable, but I think it would be just as readable to combine the last two pieces into a single handler of just returning this.year % 4 === 0

  • Responder #3 (here) - I like how this responder assigned the various conditionals involved in the logic to variable names that read like English. Then they used these variables in the evaluation of the conditions. This is how I would write things in ruby in general, so it's good to see. However, I'm not sure that the level of complexity in this problem really required this extra effort. Still, I like it.

  • Responder #4 (here) - this person solved the problem in one line, which is clever, by writing a conditional that covers all true cases. But I find it a bit more difficult to read.

  • Responder #5 (here) - this person took a simliar approach to me, but used es6 class functionality/syntax.

##Hamming My code: here

  • Responder #1 (here) - Almost exact same approach but uses charAt in comparison. Since this isn't necessary vs just using bracket notation with the index, it made my wonder why charAt exists. Through quick research it seems that bracket notation was not available until es5. Also, interesting that you can't use either approach to set the value - but charAt will fail explicitly, while bracket will fail silently.

  • Responder #2 (here) - same approach but iterates down from length to 0 vs other way around.

  • Responder #3 (here) - I really like the use of filter to solve this problem. I initially tried to think of a way to use reduce and found it to be more complicated than using the for loop. But this filter approach is very clean.

  • Responder #4 (here) - And here is the reduce version. As mentioned above, I was headed in this direction but thought it felt more complex than necessary. Although I think this is a good solution. As an aside I find it hard to read the JS documentation with respect to optional arguments like index in this case. It's hard for me to figure out where they go...

  • And... not really finding another distinct solution to comment on...

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