Skip to content

Instantly share code, notes, and snippets.

@dtinianow
Forked from anonymous/exercism.markdown
Last active October 10, 2016 01:55
Show Gist options
  • Save dtinianow/a6a7931967a917f044b23d486e592384 to your computer and use it in GitHub Desktop.
Save dtinianow/a6a7931967a917f044b23d486e592384 to your computer and use it in GitHub Desktop.

##Word Count My code: here

  • Responder #1 (here) - This approach was pretty similar to mine. They used the same exact technique to initially reformat the string as an array. Instead of a using a for loop with if/else conditionals to create the word list object, they used reduce and a ternary statement to condense the code into just a few lines.

  • Responder #2 (here) - This response used the match method with whitespace as an argument to get an array of all words. They changed each word to lower case inside of a for loop. Their conditions in the loop were basically the same as mine, except they were each condition was put on only one line. They explicitly checked in a condition was undefined, which could be implied and is not neccesary to write.

  • Responder #3 (here) - This person had a similar setup to me, except they change each word to lower case inside their loop. They use a forEach loop and a ternary statement making use of the hasOwnProperty function. This solution is succinct, but more difficult to decipher what's happening.

  • Responder #4 (here) - This person had a similar setup and approach to me. Their conditional is a ugly since they have a nested conditional and first check to see that a word exists in the array at all. They also used the hasOwnProperty function to check the list object. Their function is not very dynamic since the words function is built to always return the count function inside of it.

  • Responder #5 (here) - This response has an overly complicated setup as they string together multiple replace functions to account for whitespace and linebreaks. They use map instead of forEach which is unneccesary and are overly verbose in their statements (for example, they could use ++).

##Hamming My code: here

  • Responder #1 (here) - This first thing I noticed is this user has their function defined as a 'class', which I discovered are syntactical sugar in ES6 for prototypal JS inheritance. Unlike function declarations, classes are not hoisted. The only difference in the way they threw the error is they also explicitly wrote 'new Error'. They used reduce to iterate through one of the strands, with hash rocket syntax instead of writing out a function. This works out cleverly and efficiently, since they add the result of the boolean (0 or 1 instead of true or false) to their total sum.

  • Responder #2 (here) - This has a similar setup as mine, except the strands are not split in the initial setup, only in the loop. They used reduce to iterate through the strand and also used hash rocket syntax. They have an unneccessary if/else statement inside reduce and do not make use of the ++ shortcut.

  • Responder #3 (here) - A similar setup to mine, except each strand is saved as a constant instead of as a variable. Once again, reduce is used to iterate through. The return value of reduce is determined by a ternary statement.

  • Responder #4 ([here]http://exercism.io/submissions/323e7a5940cf4463b2df078fbe6121b4)) - This approach puts everything inside a giant if/else statement. They compare the length of each strand as the main condition. If they are the same, it goes through a for loop and if the letters are not equal, they increment by one. If they are not the same, it throws an error.

  • Responder #5 ([here]http://exercism.io/submissions/e942f01b659047b9b5d8a23f0d5628d1)) - This response was very similar to mine. They setup their whole function as a 'this' property of the Hamming object. They did not set each split as a variable and compared them only inside their conditional. They also used a proper for loop instead of a for in loop.

##Pangram My code: here

  • Responder #1 (here) - This approach does not use an alphabet hash or object in the setup. It takes the text, transforms it to lower case, and removes all non-alphabetic characters. The best part is this solution transforms the resulting string into a set, which removes all duplicates. It then measures the size of the remaining set against 26, to produce a boolean solution.

  • Responder #2 (here) - Somehow this manages to put every on one line. This is basically the same as the previous solution, except condensed into one line. It transforms it into lower case, uses regex to remove non-alphabetic characters, turns it into a set to remove duplicates, and compares the size to 26.

  • Responder #3 (here) - This solution was quite different and confusing. They used a let statement to define a function that compares two letters. They change everything to lowercase and use regex to eliminate alphabetic characters like the prior two answers. They then use a for loop and their comparing function to check something about the string that returns false if it's not true. Otherwise, the loop finishes and apparently the two strings are equal.

  • Responder #4 ([here]http://exercism.io/submissions/eef1b5a9055a4385ad8179a22afbe696)) - Another solution that uses regex and replace to remove non-alphabetic characters. It then uses a for loop to create an object that counts the number of times a letter appears in the string. He then sums up all keys, and if they equal 26, then the test passes.

  • Responder #5 ([here]http://exercism.io/submissions/3c899ca7b38f4ec2bd890b9e4d020c57)) - They also predefined an alphabet as a variable, though they save it as a set for some reason. They first check to make sure the string has any content at all. Then they instatiate an empty set to hold used characters. Then there are two for loops - first to add all chars to the used to set, and then to check each character of the alphabet to see if it appears in used. Otherwise it will return true.

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