Last active
March 30, 2020 23:34
-
-
Save Mastersam07/fbca98caf45a63bb3bb3673df1f9940e to your computer and use it in GitHub Desktop.
a function that returns the index of a particular resistor color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| print(getIndex('Red')); | |
| } | |
| // a function that returns the index of a particular resistor color | |
| // taking the color as argument | |
| int getIndex(color) { | |
| var dict = { | |
| 'Black': 0, | |
| 'Brown': 1, | |
| 'Red': 2, | |
| 'Orange': 3, | |
| 'Yellow': 4, | |
| 'Green': 5, | |
| 'Blue': 6, | |
| 'Violet': 7, | |
| 'Grey': 8, | |
| 'White': 9 | |
| }; | |
| return dict[color]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment