Created
December 31, 2023 15:27
-
-
Save jorwan/6bce751e7ace6ac7064897e7df8fcbb6 to your computer and use it in GitHub Desktop.
Test - Calling multiple times keep same result
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() { | |
print("Current list"); | |
var l = [1,5,2,null,0]; | |
print(l); | |
print("Sorted List"); | |
for(int i=0;i<10;i++){ | |
sortIt(l); | |
print(l); | |
}; | |
} | |
void sortIt(list){ | |
list.sort((a, b) { | |
int result; | |
if (a == null) { | |
result = 1; | |
} else if (b == null) { | |
result = -1; | |
} else { | |
// Ascending Order | |
result = a.compareTo(b); | |
} | |
return result; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment