Skip to content

Instantly share code, notes, and snippets.

@allindow
Forked from anonymous/exercism.markdown
Last active October 9, 2016 22:04
Show Gist options
  • Save allindow/7af53476fd316c7a4293a82b31e7adae to your computer and use it in GitHub Desktop.
Save allindow/7af53476fd316c7a4293a82b31e7adae to your computer and use it in GitHub Desktop.
Length Points Week
1 to 6 hours 25 Week 2

Exercism Comparisons

LEAP

  • Mine

  • #1 - I have Year set to a variable and they have theirs set to function. Not sure which is the correct way. They don't have a nested if statement - I knew that was ugly, but was just trying to make it pass and didn't refactor. They're just checking if it's divisible by 4 and not by 100, then return true. If that is false, then it goes to check if it's divisble by 400 and hten it returns true. If neither of those work it returns false. In mine I'm check if it's divisible by 4, and if it is then checks if it's not divisible by 100, then return true, or if it's divisible by 400, then return true, otherwise return false. And if it's not divisble by 4 then return false. I could have combined more of these conditionals.

  • #2 Like me, they are using var to set Year. Theirs is very interesting and I think pretty readable. They created a isDivisible function with they use in their isLeap function for each conditional. isLeap returns true or false for if the number is divisible by 4 && (not divisible by 100 OR divisible for 400). I really like the isDivisible function.

  • #3 This person uses a class, and I've never used a class in Javascript so it doesn't look familiar to me. But it's basically just return ((year % 400 === 0)||(year % 4 === 0)); so if it's divisble by 400 OR divisible by 4, it returns true. Otherwise returns false. I'm kind of blown away by the simplicity!

  • #4 This person used nested if statements just like me. It isn't pretty.. neither is mine. Immediately I think to myself "There's a better way to do that..."

  • #5 This person just had one if statement, else return false. They used && and || in that one conditional. For some reason I didn't use either one of those.

BOB

  • Mine

  • #1 First thing I noticed they did that I didn't do was the use of variables to make their code more readable. I've been really bad about that with JS. I'm still learning Javascript methods and start scrambling and tend to forget about making it readable. They used a conditional to check for an empty string but I used trim which removes the whitespace on each side of a string and then checked the length. I'm confused about the middle if block because it looks like they all return the same thing? Aside from having the variables for readability I'm not sure this implementation is better than mine.

  • #2 This one doesn't take as many lines, but it uses regex in every conditional. I like regex and use it when I need it, but I don't think it's something that should be used like this because it's not readable.

  • #3 This one uses regex for two of their conditionals also, BUT, they name constants to make it clear what their regex is testing for. I actually really like this a lot. I think the hey function is super readable.

  • #4 I feel like this one is more similar to mine in that it doesn't rely on regex (although mine does have one regex), and it converted to uppercase/lowercase for conditionals. But they don't have nested if statements like I do. Again, I could've combined some of my conditionals to get rid of my nested if statements.

  • #5 I like that they set a response dictionary so they could just call response.yell or response.silence. The conditionals look similar to mine but with no nested if statements.

ANAGRAM

  • Mine

  • #1 They used a class and static and I'm not sure what static is. They also use ...args which I think takes separate arguments and puts them into a dictionary with the key being their index and the value being the argument? Interesting.

  • #2 There is a lot going on here.. The naming conventions are good but it would have been more readable if they were pulled out into functions outside of the loop. In this case I think my code has less if statements, but my one conditional is absurdly long. Like I was saving all my && and || from previous exercisms for this one :\

  • #3 lots of naming things, lots of constants. Even though I have one long conditional, I find my code easier to follow than this. But there are a lot of things here that I didn't think to use like Array.from(arguments), reduce, concat

  • #4 I think it's clever that they added attributes to Anagram itself for the pattern and the sorted lettered version of the word so that you can just call that in the match method rather than having to do all the work there. There's a ternary, there's filter...The last return is kind of a long conditional. I mostly like the additional attributes on Anagram and think I could've cleaned things up quite a bit by doing that.

  • #5 They didn't prototype. Is prototyping unneccessary sometimes maybe? But then they do prototype Array on the arguments if they aren't in an array. They're using a for loop and I'm using map, but both have the really long conditional. Overall I think this is really similar to my implemtnation.

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