Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add analyzer for rna-transcription #53

Open
SleeplessByte opened this issue Sep 26, 2019 · 0 comments
Open

Add analyzer for rna-transcription #53

SleeplessByte opened this issue Sep 26, 2019 · 0 comments

Comments

@SleeplessByte
Copy link
Member

SleeplessByte commented Sep 26, 2019

This issue is for discussion and assignment for the rna-transcription core exercise in the javascript track.

🔗 implementation | mentor-notes | problem-specification


This exercise focuses on

Optimal solution

const TRANSCRIPTION = {
  C: 'G',
  G: 'C',
  A: 'U',
  T: 'A',
};

export function toRna(sequence) {
  return sequence
    .split('')
    .map(nucleotide => TRANSCRIPTION[nucleotide])
    .join('')
}

Variations include Set or Map with #get, which are valid!

Variations (approvable without comment)

String destructuring can also be used:

return [...sequence].map(/**/).join('')

String#replace can also be used:

return sequence.replace(/./g, (nucleotide) => /* */)

Variations include replacing only the "known" nucleotides:

sequence.replace(/[CGAT]g/, (nucleotide) => /* */)

Helper function variation

Instead of an anonymous function, a helper function may be used:

function transcribe(nucleotide) {
  return TRANSCRIPTION[nucleotide]
}

This also allows for a version without a mapping object:

function transcribe(nucleotide) {
  switch(nucleotide) {
    case 'C': { return 'G' }
    case 'G': { return 'C' }
    case 'A': { return 'U' }
    case 'T': { return 'A' }
  }
}

SHOULD comment and disapprove

Cases we SHOULD comment on with this analyzer:

  • Use an Object to keep track of the mapping instead of conditionals.
  • Use iteration via String#split or String#replace instead of using for/forEach with Array#push
  • Discourage Array#reduce for this particular solution, because it creates a lot of intermediary strings (more than the split approach), except if the rest of the solution is correct (then you can mention it but approve). Using reduce requires more interpretation by the reader to follow, change and maintain.
  • Discourage String#substring with foreach iteration, because character iteration via split('') is more idiomatic and maintainable than substring with 1. Using split('') requires less interpretation by the reader to follow, change and maintain.

Approach

The suggested approach is to:

  • detect which type of solution it is (switch, map, or for/forEach)
  • make sure the optimal solution is correctly handled. You can use the batch runner to generate output for all fixtures.
  • go from there by adding paths to disapprove.
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

No branches or pull requests

1 participant