Created
March 22, 2022 14:59
-
-
Save hotdang-ca/66352776d508ec47d8c827d608b9a5f0 to your computer and use it in GitHub Desktop.
Cannabis Potency conversation
This file contains 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
class Cannabis { | |
final String uom; | |
final num p; | |
Cannabis(this.uom, this.p); | |
} | |
void main() { | |
List<Cannabis> product = [ | |
Cannabis('%', 5), | |
Cannabis('%', 10), | |
Cannabis('%', 15), | |
Cannabis('%', 20), | |
Cannabis('%', 25), | |
Cannabis('mg/g', 5), | |
Cannabis('mg/ml', 10), | |
Cannabis('mg', 15), // this one wont be able to convert | |
Cannabis('mg/ml', 20), | |
Cannabis('mg/g', 25), | |
Cannabis('mg/ml', 50), | |
]; | |
for (final c in product) { | |
String newUom = ''; | |
num newPotency = 0; | |
if (c.uom == '%') { | |
newUom = 'mg/mL'; // ML for wet, MG for dry | |
newPotency = c.p * 10; | |
} else if (c.uom == 'mg/g' || c.uom == 'mg/ml') { | |
newUom = '%'; | |
newPotency = c.p / 10; | |
} | |
if (newPotency != 0) print('We converted ${c.p} ${c.uom} to ${newPotency} ${newUom}'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment