Change Exercise is now ECMAScript ready#362
Conversation
matthewmorgan
left a comment
There was a problem hiding this comment.
@RobinCsl thanks for taking this on!
There are a few things we could do to make this more idiomatic ES6, and maybe then tighten up some other things .
Can you start with the comments I've left and we'll go from there? Thanks!
| expect(result).toEqual([25]); | ||
| }); | ||
|
|
||
| xtest('multiple coins coin', () => { |
There was a problem hiding this comment.
Should this read multiple coin change, as in the canonical file?
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| xtest('test less than the smallest currency represented', () => { |
There was a problem hiding this comment.
Should this word currency instead be coin?
| expect(test).toThrowError(Error, message); | ||
| }); | ||
|
|
||
| xtest('test a large value that the currency cannot represent', () => { |
There was a problem hiding this comment.
Should this word currency instead be coin? (as above)
| } | ||
| } | ||
|
|
||
| Change.prototype.calculate = (coinArray, target) => { |
There was a problem hiding this comment.
In ES6 we would want to see the Change class written something like this:
class Change {
calculate(coinArray, target) {
...
}
}The preferred pattern is like you have done for your Candidate class. The pattern of extending the prototype is an ES5 pattern, so we'll want to use the newer paradigm here.
| const sum = candidate.getSum(); | ||
|
|
||
| if (candidate.getSum() <= target && | ||
| typeof (candidates[sum]) !== 'number' && |
There was a problem hiding this comment.
I'm wondering if this wouldn't be more readable if the conditional were extracted into a named function instead?
Also, the indenting is a little unusual here. You could run the linter against your code in "fix mode" to perhaps take care of a lot of these things automatically. Let me know if I can provide some assistance on how to do that.
| // is everthing searched? | ||
| const isDone = () => { | ||
| let done = true; | ||
| for (let i = 0; i < candidates.length; i += 1) { |
There was a problem hiding this comment.
Since you don't need the index i here, you might consider using the now available for-of instead, like so:
for (let candidate of candidates){
...
}This would allow you to eliminate the indirection of using the index variable i and the temporary variable temp.
|
|
||
| // get the next unsearched member of the candidate array | ||
| const getNext = () => { | ||
| for (let i = 0; i < candidates.length; i += 1) { |
There was a problem hiding this comment.
Same remarks about the for-of as above.
|
|
||
| // copy the curent coins into it and add the new coin type | ||
| for (let i = 0; i < current.getCoins().length; i += 1) { | ||
| candidate.addCoin(current.getCoins()[i]); |
There was a problem hiding this comment.
Again, you have two loops that use index variables that you don't really need. Hit it with some ES6!!!
|
Thank you very much for all your comments, they were really helpful and constructive. I hope that the code is clearer and better now. Let me know if there is anything else I should improve! :) so I did without them, which actually produced more readable code in my opinion.) |
| $ npm test | ||
| ``` | ||
|
|
||
| In many test suites all but the first test have been skipped. |
There was a problem hiding this comment.
Probably should change this to read "In the test suite, all tests but the first have been skipped." I'm not sure where this language came from, but I know it's present in many exercises.
|
Awesome! I'm glad you feel the review was helpful and the code is better for it. I had one minor language change for the README if you don't mind, otherwise looks ready to merge. |
|
Just updated the README file :) |
|
Great! Mind squashing to one commit? If you need assistance with this, I'm happy to help. |
|
I managed to squash the commits for this one too! I'll try again on #365! |
|
@matthewmorgan approved the changes, and commits have been squashed. Merging... |
Grouped all tests under a single describe Ordered the tests in a more logical way. All tests except the first one are skipped. Removed mention of enabling tests by changing xdescribe to describe. Implement exercise isbn-verifier (exercism#366) [Housekeeping] Upgrade jest (exercism#368) * Use `package-lock.json` instead of `yarn.lock` * Upgrade jest and babel-jest to latest versions Jest to 21.2.1 babel-jest to 21.2.0 Change Exercise is now ECMAScript ready (exercism#362) Transpose Exercise is ECMAScript ready (exercism#364) Upgrade jest Protein Translation is ECMAScript ready (exercism#365) (exercism#365) Update setup links in all READMEs (exercism#371) Update all setup links in exercise READMEs from http://exercism.io/languages/ecmascript to http://exercism.io/languages/ecmascript/installation Closes exercism#370 Updated setup link
Grouped all tests under a single describe Ordered the tests in a more logical way. All tests except the first one are skipped. Removed mention of enabling tests by changing xdescribe to describe. Implement exercise isbn-verifier (exercism#366) [Housekeeping] Upgrade jest (exercism#368) * Use `package-lock.json` instead of `yarn.lock` * Upgrade jest and babel-jest to latest versions Jest to 21.2.1 babel-jest to 21.2.0 Change Exercise is now ECMAScript ready (exercism#362) Transpose Exercise is ECMAScript ready (exercism#364) Upgrade jest Protein Translation is ECMAScript ready (exercism#365) (exercism#365) Update setup links in all READMEs (exercism#371) Update all setup links in exercise READMEs from http://exercism.io/languages/ecmascript to http://exercism.io/languages/ecmascript/installation Closes exercism#370 Updated setup link
Grouped all tests under a single describe Ordered the tests in a more logical way. All tests except the first one are skipped. Removed mention of enabling tests by changing xdescribe to describe. Implement exercise isbn-verifier (#366) [Housekeeping] Upgrade jest (#368) * Use `package-lock.json` instead of `yarn.lock` * Upgrade jest and babel-jest to latest versions Jest to 21.2.1 babel-jest to 21.2.0 Change Exercise is now ECMAScript ready (#362) Transpose Exercise is ECMAScript ready (#364) Upgrade jest Protein Translation is ECMAScript ready (#365) (#365) Update setup links in all READMEs (#371) Update all setup links in exercise READMEs from http://exercism.io/languages/ecmascript to http://exercism.io/languages/ecmascript/installation Closes #370 Updated setup link
Grouped all tests under a single describe Ordered the tests in a more logical way. All tests except the first one are skipped. Removed mention of enabling tests by changing xdescribe to describe. Implement exercise isbn-verifier (exercism#366) [Housekeeping] Upgrade jest (exercism#368) * Use `package-lock.json` instead of `yarn.lock` * Upgrade jest and babel-jest to latest versions Jest to 21.2.1 babel-jest to 21.2.0 Change Exercise is now ECMAScript ready (exercism#362) Transpose Exercise is ECMAScript ready (exercism#364) Upgrade jest Protein Translation is ECMAScript ready (exercism#365) (exercism#365) Update setup links in all READMEs (exercism#371) Update all setup links in exercise READMEs from http://exercism.io/languages/ecmascript to http://exercism.io/languages/ecmascript/installation Closes exercism#370 Updated setup link
No description provided.