Skip to content

Protein translation#365

Merged
matthewmorgan merged 1 commit intoexercism:masterfrom
RobinCsl:protein-translation
Oct 29, 2017
Merged

Protein translation#365
matthewmorgan merged 1 commit intoexercism:masterfrom
RobinCsl:protein-translation

Conversation

@RobinCsl
Copy link
Copy Markdown
Contributor

Same comment as for PR #364, I did some kind of manual rebase so that there shouldn't be any conflicts. Looking forward to having your comments.

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 looks great! I had a couple of style suggestions, but nothing critical. Change if you like, if not, I'm OK with things as they are.

});

xtest('Invalid codon throws error', () => {
expect(() => { translate('LOL'); }).toThrow(new Error('Invalid codon'));
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.

We could clean this up a little like so:

expect(() => translate('LOL')).toThrow(new Error('Invalid codon'));

default:
return 'INVALID';
}
};
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.

Nothing at all wrong with the massive switch statement, but I sometimes like an alternative approach to these sorts of things, using an object. EG:

const ACID_PROTEIN_MAP = {
  'AUG': 'Methionine',
  'UUU': 'Phenylalanine',
  'UUC': 'Phenylalanine',
// and so on...
};

const getProtein = codon => ACID_PROTEIN_MAP[codon] || 'INVALID';

It remains very readable and gets what's essentially configuration out of your logic. In production, you might pull the config out even further: this makes it easy to adjust the mapping without having to redeploy code.

@RobinCsl
Copy link
Copy Markdown
Contributor Author

Implemented the changes proposed. I tried to extract the config in an external json file, but it seemed to cause more complications, so I finally opted for the easier solution of setting this variable in the same file.

"UAA": "STOP",
"UAG": "STOP",
"UGA": "STOP"
}
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.

Gorgeous! Awesome indeed.

@matthewmorgan
Copy link
Copy Markdown
Contributor

@RobinCsl I see why you're having a problem-- I think the makefile that runs the test suite does not copy your config file over...not a problem to include it in the example file.

It's nice, though, right? The config is ~ 1/2 the size of the switch statement and just as clear.

This PR looks good to me, if you could please squash the commits we'll merge it.

@rchavarria
Copy link
Copy Markdown
Contributor

Extract configuration to external files is usually a good idea in the real world. In exercism we try to get just three files: readme, tests and production/solution. Keeping all tests and all solution code in one file each make solution management much easy.

I think that could be the reason why the Makefile doesn't take care of other files. It only knows about the files described above.

Sorry @RobinCsl for causing you some struggles with that. And thanks for implementing this exercise for the track.

@RobinCsl RobinCsl force-pushed the protein-translation branch from 0865614 to 1a29710 Compare October 29, 2017 13:36
RobinCsl added a commit to RobinCsl/ecmascript that referenced this pull request Oct 29, 2017
@RobinCsl RobinCsl force-pushed the protein-translation branch from 559b7d9 to 2931760 Compare October 29, 2017 13:41
RobinCsl added a commit to RobinCsl/ecmascript that referenced this pull request Oct 29, 2017
@RobinCsl
Copy link
Copy Markdown
Contributor Author

I tried to squash all the commits together, but every time I push there would still be a conflict with master, even though I rebased off upstream/master. So I believe I will need assistance with squashing my commits. Sorry!

@RobinCsl RobinCsl force-pushed the protein-translation branch from 90c87f7 to 980058d Compare October 29, 2017 14:14
RobinCsl added a commit to RobinCsl/ecmascript that referenced this pull request Oct 29, 2017
@RobinCsl RobinCsl force-pushed the protein-translation branch from 980058d to 4e42bdd Compare October 29, 2017 14:16
RobinCsl added a commit to RobinCsl/ecmascript that referenced this pull request Oct 29, 2017
@RobinCsl
Copy link
Copy Markdown
Contributor Author

Looks like I managed now, I guess I had not rebased in the right way.

@rchavarria
Copy link
Copy Markdown
Contributor

Sorry 😞 I think merging PRs #362 and #364 created conflicts in this one.

@RobinCsl RobinCsl force-pushed the protein-translation branch from 4e42bdd to 816f3a7 Compare October 29, 2017 16:30
@RobinCsl
Copy link
Copy Markdown
Contributor Author

No problem, should be fine now :) Thank you!

@matthewmorgan
Copy link
Copy Markdown
Contributor

@RobinCsl glad to hear you got it sorted. I did not see you were having trouble, hope it wasn't too frustrating. Sometimes it can be a bit tricky to resolve the conflicts.

Thanks for the contribution!

@matthewmorgan matthewmorgan merged commit b6bf7a3 into exercism:master 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