-
-
Notifications
You must be signed in to change notification settings - Fork 946
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
Ruby/Resistor Colors: Add Mentor Notes #853
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,33 @@ | ||||||
Resistor Colors is a side exercise, unlocked by Hello World | ||||||
|
||||||
### New Concepts | ||||||
Array, Array#index, `map`, Constant, chaining methods | ||||||
|
||||||
### Minimal solution for approval | ||||||
```ruby | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest removing the whitespace above |
||||||
class ResistorColors | ||||||
|
||||||
COLOR_CODES = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Default style via rubocop WordArray and rubocop MutableConstant. Add below this solution that:
|
||||||
|
||||||
def self.value(colors) | ||||||
colors.map { |color| COLOR_CODES.index(color) }.join.to_i | ||||||
end | ||||||
|
||||||
end | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove whitespace between final |
||||||
``` | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add note about acceptable variations include using a |
||||||
### General | ||||||
This is the very first Array exercise, and the first loop. Introducing `map` is key in this exercise. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Isn't this set up as a bonus exercise? (reference) |
||||||
|
||||||
### Talking points | ||||||
- _`%w` notation_: for arrays of strings. Link to [styleguide](https://github.com/rubocop-hq/ruby-style-guide#percent-w) | ||||||
- _chaining methods_ after a block (especially when people use a local variable for `join.to_i` | ||||||
- _`each` vs `map`_: this explains the difference: [each vs map](https://learn.onemonth.com/ruby-tutorial-map-vs-each/) | ||||||
- _variable vs constant_: this article explains just that: [var vs constant](https://ruby-doc.org/docs/ruby-doc-bundle/Tutorial/part_01/variables.html) | ||||||
- _freeze_: this post has exactly the right level of information: [freeze](https://freelancing-gods.com/2017/07/27/an-introduction-to-frozen-string-literals.html); no need to dive deeper into (im)mutability. | ||||||
|
||||||
|
||||||
### Changelog | ||||||
First introduced 2019 Mar 10 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should have a specific format for the changelog. Maybe something like:
Maybe HighScores can be a good guide as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add blank line between header and content, following default markdownlint