Skip to content

Change Exercise is now ECMAScript ready#362

Merged
rchavarria merged 1 commit intoexercism:masterfrom
RobinCsl:master
Oct 29, 2017
Merged

Change Exercise is now ECMAScript ready#362
rchavarria merged 1 commit intoexercism:masterfrom
RobinCsl:master

Conversation

@RobinCsl
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@matthewmorgan matthewmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

Comment thread exercises/change/change.spec.js Outdated
expect(result).toEqual([25]);
});

xtest('multiple coins coin', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this read multiple coin change, as in the canonical file?

Comment thread exercises/change/change.spec.js Outdated
expect(result).toEqual([]);
});

xtest('test less than the smallest currency represented', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this word currency instead be coin?

Comment thread exercises/change/change.spec.js Outdated
expect(test).toThrowError(Error, message);
});

xtest('test a large value that the currency cannot represent', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this word currency instead be coin? (as above)

Comment thread exercises/change/example.js Outdated
}
}

Change.prototype.calculate = (coinArray, target) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread exercises/change/example.js Outdated
const sum = candidate.getSum();

if (candidate.getSum() <= target &&
typeof (candidates[sum]) !== 'number' &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread exercises/change/example.js Outdated
// is everthing searched?
const isDone = () => {
let done = true;
for (let i = 0; i < candidates.length; i += 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread exercises/change/example.js Outdated

// get the next unsearched member of the candidate array
const getNext = () => {
for (let i = 0; i < candidates.length; i += 1) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remarks about the for-of as above.

Comment thread exercises/change/example.js Outdated

// 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]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, you have two loops that use index variables that you don't really need. Hit it with some ES6!!!

@RobinCsl
Copy link
Copy Markdown
Contributor Author

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! :)
(Also, just so you know, I had this error when running npm run lint if there were for...of loops:

error  iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations  no-restricted-syntax

so I did without them, which actually produced more readable code in my opinion.)

Comment thread exercises/change/README.md Outdated
$ npm test
```

In many test suites all but the first test have been skipped.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@matthewmorgan
Copy link
Copy Markdown
Contributor

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.

@RobinCsl
Copy link
Copy Markdown
Contributor Author

Just updated the README file :)

@matthewmorgan
Copy link
Copy Markdown
Contributor

Great! Mind squashing to one commit? If you need assistance with this, I'm happy to help.

@RobinCsl
Copy link
Copy Markdown
Contributor Author

I managed to squash the commits for this one too! I'll try again on #365!

@rchavarria
Copy link
Copy Markdown
Contributor

@matthewmorgan approved the changes, and commits have been squashed. Merging...

@rchavarria rchavarria merged commit ef5e51d into exercism:master Oct 29, 2017
@rchavarria rchavarria mentioned this pull request Oct 29, 2017
MattH-be added a commit to MattH-be/ecmascript that referenced this pull request Oct 30, 2017
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
MattH-be added a commit to MattH-be/ecmascript that referenced this pull request Oct 31, 2017
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
matthewmorgan pushed a commit that referenced this pull request Oct 31, 2017
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
laurmurclar pushed a commit to laurmurclar/ecmascript that referenced this pull request Nov 4, 2017
laurmurclar pushed a commit to laurmurclar/ecmascript that referenced this pull request Nov 4, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants