Skip to content

Instantly share code, notes, and snippets.

@jorwan
Created December 31, 2023 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorwan/6bce751e7ace6ac7064897e7df8fcbb6 to your computer and use it in GitHub Desktop.
Save jorwan/6bce751e7ace6ac7064897e7df8fcbb6 to your computer and use it in GitHub Desktop.
Test - Calling multiple times keep same result
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