Skip to content

Instantly share code, notes, and snippets.

@erinnachen
Last active May 8, 2016 18:17
Show Gist options
  • Save erinnachen/15a33333a4c30f61fe547e1d626fea78 to your computer and use it in GitHub Desktop.
Save erinnachen/15a33333a4c30f61fe547e1d626fea78 to your computer and use it in GitHub Desktop.
Comparisons of Javascript Exercism Implementations

Bob

My code: here

  • Responder #1 (here) - This responder took largely the same approach as me but used methods that may be considered higher in the abstraction tree (e.g. endsWith).

  • Responder #2 (here) - This exercise does not necessarily lend itself to many variations. The responder here utilizes the power of explicit returns to take remove else if constructs. The responder does not necessarily need to extract the string into an array to utilize bracket accessing.

  • Responder #3 (here) - This responder has a similar approach to all the other responders. There is inconsistent use (perhaps?) of the == and === comparators.

  • Responder #4 (here) - This responder utilizes functional JS versus the more OO style. There is the use of a class definition here; would this be different if there wasn't an interface rigidly defined by the test suite? Also can you namespace the defined constants here?

  • Responder #5 (here) - This responder utilizes a global variable result instead of using an if/else construct. The code could be DRY-ed out with some assumption of the format of the input to the helper functions.

Word Count

My code: here

  • Responder #1 (here) - This responder has a very similar to approach to my own. Minor differences are: when the toLowerCase() function occurs, I utilized a variable words to avoid repeatedly accessing the words array by index (this was for readability). The question of using hasOwnProperty versus seeing if the object responds to a certain key is interesting. The other question I have is whether checking of argument type is necessary/preferred in JS.

  • Responder #2 (here) - This responder brought in functions from lodash! There was definitely novel things here: the implementation uses consts instead of vars, also the use of functions from lodash. Also, this responder has fairly rigid matchers in their parsing function /[ \t\n]/ instead of a more generic /\s/.

  • Responder #3 (here) - This responder has a very similar to approach to my own. A comment I have is that the string can be split on the regex match instead of replacing the matching with a space and then splitting on all spaces. Another comment is that JS is similar to Ruby that there are concepts of truthiness and falsiness, so perhaps a check like === undefined is redundant. Is there a preference for Object.create(null) vs {} for defining an object literal?

  • Responder #4 (here) - This responder has a more condensed form of solving the problem. I like the use of val[current] = val[current] + 1 || 1, instead of if/else statements that the other solutions (including my own) have been using. The let construct is a new, and suggests that functional JS is not necessarily used as often at least on the exercism front.

  • Responder #5 (here) - This responder has similar solutions to myself and Responders #1 and #3. An interesting comment on this exercism was: "While this solution passes all the tests in the suite, by not dealing with "own properties" in some fashion (there are several ways of dealing with "own properties"), it does leave itself open to abuse from other code."

Pangram

My code: here

  • Responder #1 (here) - This responder had a similar approach. This responder uses the reduce method to iterate through the characters array. I found that my approach may have been redundant in that I check equality to the sorted string where I also have a unique character function. I probably need to use better variable names.

  • Responder #2 (here) - This responder uses the class definition versus prototype definitions. I really like the use of Set, instead of unique chars!

  • Responder #3 (here) - This user decided to build out an alphabet object that stores the count of letters seen. It seems like there is a lot of redundancy in this implementation.

  • Responder #4 (here) - This responder took a similar approach to Responder #2 with the creation of a set, and if similar to Responder #1 with the check that the unique set has length 26. The interesting part here is the use of global function declarations for isLetter and Uniq. I don't know if this is standard. The responder went to the trouble of extracting methods, but left the string normalization in the isPangram function.

  • Responder #5 (here) - This responder maps each letter to an array where the index is the integer corresponding to the ASCII code of the ltter. This seems to make the readability of the code more difficult. Something interesting that the responder used was this._candidate. I do not yet know how to implement private or privileged functions in JS.

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