Skip to content

Instantly share code, notes, and snippets.

@pwentz
Last active October 14, 2016 13:22
Show Gist options
  • Save pwentz/9444bb74068c50886778f0a36e3a8937 to your computer and use it in GitHub Desktop.
Save pwentz/9444bb74068c50886778f0a36e3a8937 to your computer and use it in GitHub Desktop.
## Isogram
My code: http://exercism.io/submissions/a2c21ec6705b418090c8098954cf5d6d
1st Responder(http://exercism.io/submissions/4537749e38d94932b330f9eabd094ef2)
The way this Isogram function was tested, I'm sure this is one of many solutions making use of RegEx. Although I've been trying to avoid using RegEx, it seems like this test is a good place to use it if you know how. Also, I've never seen a Set actually used either - so that's pretty cool.
2nd Responder(http://exercism.io/submissions/275ed5af4fb24c0582b082b37b85c569)
It's refreshing to see comments in other people's code to explain what's going on - especially when it comes to exercisms,
where everybody is trying to cram a solution is as few lines as possible. This is the first solution if seen using RegEx to explicitly check for diacrtics. Also, interesting to see so many people reaching for a for loop over a simple iterator to make their lives easy. It's strange to see how enumerables are our go-to when it comes to iteration while JS developers are raised on for loops.
3rd Responder(http://exercism.io/submissions/95b645aef315460f8c4ba83abd1ddfa2)
It's nice to see a solution that does not use Regular Expressions. I also am a huge fan of filter, so it's cool to see that tool being used. However it seems almost redundant to code `var wrd = this.word ; wrd = wrd.toLowerCase()`. This is the other end of the spectrum from most exercism solutions, which seem to try to chain at least 3-4 methods on every line.
4th Responder(http://exercism.io/submissions/a5df3efc757e45b7904a6f06dfde844a)
I like this solution because they went a little out of the box and assigned text as a property on the instance. This is a neat approach because it's more OOP than many other solutions I've found, which just compute the thing and return an answer.
5th Responder(http://exercism.io/submissions/804d3448a8f345b294ac27ab2e99c3ba)
This is probably the most concise solution that I've seen, making use of both RegEx and the Set constructor that JS has built in. Overall a pretty impressive solution, it's interesting to learn about the similarities and differences between the JS Set and Ruby Struct.
## Flatten-Array
My code: http://exercism.io/submissions/b0aed5133e7d4b848842376fffd41f05
1st Responder(http://exercism.io/submissions/01bf9048a39b46ae88d13fca5484070b)
This response followed a similar format to many others I had seen. The tricky part about this exercise is adjusting your code
so that it can recognize and flatten a simple nested array [[]]. Although I like the `typeof` approach, I think I was able to
sidestep that problem by changing the elements in the array to strings (which .join does anyway). This makes the empty array
an empty string, which is falsey in JS. So all I had to do was check for the element before making any calculations.
2nd Responder(http://exercism.io/submissions/758b04d58c764bf4aa4026532bc4e14f)
I thought this one was particularly interesting because and noteworthy because of its syntax and logic. I keep seeing the pattern of explicitly checking if an object returns null or undefined when both are falsey. Syntax-wise, it's interesting to see the use of a for...of loop over a .forEach method - I would be curious to hear the argument over one or the other. Lastly, I'm not sure what the spread syntax on line 8 is doing, it appears as if the dev is then calling the function itself recursively at that point, which would be pretty cool - however I'm not sure.
3rd Responder(http://exercism.io/submissions/c0f52959b7eb444cbfaa885841883123)
The thing that I like about this solution is that the dev isn't afraid to extract logic out to smaller functions. I'm also a fan of passing other functions as arguments to take care of the iteration logic, I think it makes code much more readable that way. This solution follows the same suit as the others to check if an empty array is nested in the array. I'd be interested in finding a solution that doesn't use an if statement.
4th Responder(http://exercism.io/submissions/74ea940db9a34531a38a658eb9666461)
I like this solution a lot because it is both concise and readable. It's pretty amazing how much more readable your code becomes when you use an iterator like `.forEach` over `for (var i; i < collection.length; i++)`. Also, I like the use of the
one line conditionals that the dev used.
5th Responder(http://exercism.io/submissions/73afb2c49b5341f69fd4b702ed71e11a)
I also like the readability of this solution. I think it's probably a good idea in JS to include the state in the variable names when your manipulating an object. By having vars like `flattenedArray` and `unflattenedArray`, the code becomes much easier to follow.
## Sieve
My code: http://exercism.io/submissions/87a30ff6a8bb46ad8c0979da6986436d
1st Responder(http://exercism.io/submissions/9608c1e8ec334de9a7ec53ae8b40574c)
This was probably the most readable version I've seen since the developer abstracts some of the logic (that I had nested) into
a separate function. However there is something inherently frustrating about the way they had written that function - specifically `if (num % i === 0) return false`. Why didne't the dev just bypass the if statement and return `num % i !== 0`?
2nd Responder(http://exercism.io/submissions/f44ac72491c641cb8c6c8887e5799e4c)
I find this one pretty long and hard to follow. With variable names like `maskList` and `nList`, it's very hard to follow what's going on with this code.
3rd Responder(http://exercism.io/submissions/1d4cedd4a0c94e07927eed54fa455348)
I think this solution took a pretty interesting approach by putting the numbers in an array and then iterating through them, as opposed to just counting up using a `for` loop. I can see where this approach might be preferred because iterations are probably still the first thing a dev reaches for if they're coming from Ruby. Also, very strange to see something like `Array.from(array)`, when the initial value coming in is already an array. If they wanted to create a copy, there's always the spread syntax: `const filtered = [...array]` !
4th Responder(http://exercism.io/submissions/63a7bf8872374d9fa086be45144321ce)
I like this response because of it's readability. I also like the use of `found` as a var and switching the state from true to false...that seems like a very JavaScript-y way to solve the problem. Also, interesting use of opting for `new Array()` over an array literal.
5th Responder(http://exercism.io/submissions/172b95b6acfd4c87869e3446bbd40cd0)
I think this solution is funny because it's very similar to mine. I think this one is much easier to follow with the use of both a `primes` array and a `not_primes` arrays. However I've never seen a `for` loop used with an `if` statement both on the same line. I'm curious as to how that would compute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment