Last active
September 9, 2019 11:58
-
-
Save mdecourse/c129d7cb1b1cf5e2d714d0d6d5427b31 to your computer and use it in GitHub Desktop.
Sort list with string elements
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
void main() { | |
var prices = ['99', '27', '10000', '20000000']; | |
prices.sort((String a, String b)=>int.parse(a).compareTo(int.parse(b))); | |
print('Lowest price is ${prices[0]}!'); | |
} | |
/* | |
Dart2 strong sound typing example | |
void main() { | |
List<int> prices = ['99', '27', '10000', '20000000']; | |
// Sort in place from smallest to largest | |
prices.sort(); | |
print('Lowest price is ${prices[0]}!'); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment