Last active
March 1, 2023 17:55
-
-
Save ulisseshen/02b18e386cfa27238a265728b5ddd6bf to your computer and use it in GitHub Desktop.
Um sistema sismples mostrando a ordenação ASC e DESC de uma lista de números em Dart
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() { | |
List<int> numeros = [0, 5, 2, 4, 7, 1, 9, 6, 3, 8]; | |
print(numeros); | |
// [0, 5, 2, 4, 7, 1, 9, 6, 3, 8] | |
//ASC - ascendente | |
numeros.sort(); | |
print(numeros); | |
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
//DESC - descendente | |
numeros.sort((a,b)=> -a.compareTo(b)); | |
print(numeros); | |
// [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment