Skip to content

Instantly share code, notes, and snippets.

@mdecourse
Last active September 9, 2019 11:58
Show Gist options
  • Save mdecourse/c129d7cb1b1cf5e2d714d0d6d5427b31 to your computer and use it in GitHub Desktop.
Save mdecourse/c129d7cb1b1cf5e2d714d0d6d5427b31 to your computer and use it in GitHub Desktop.
Sort list with string elements
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