Created with <3 with dartpad.dev.
Created
October 18, 2022 10:08
-
-
Save luffynas/65569873e3e4a5a640d9446f7205ef41 to your computer and use it in GitHub Desktop.
zealous-villa-3171
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 animals = <Animal>[ | |
Animal(id: 1,name: 'Dophon', group: 'mammal'), | |
Animal(id: 2,name: 'Snake', group: 'reptile'), | |
Animal(id: 3,name: 'Baracuda', group: 'fish'), | |
Animal(id: 4,name: 'Cat', group: 'mammal'), | |
Animal(id: 5,name: 'Elephant', group: 'mammal'), | |
Animal(id: 6,name: 'Kakak Tua', group: 'bird'), | |
Animal(id: 7,name: 'Komodo', group: 'reptile'), | |
]; | |
// Soal 1: search with group 'mamal' | |
// final mammalGroup = <Animal>[]; | |
// final searcMammal = animals.where((e) => e.group == 'mammal'); | |
// mammalGroup.addAll(searcMammal); | |
// for(var mammal in mammalGroup){ | |
// print('Name is :: ${mammal.name} and Group is ${mammal.group}'); | |
// } | |
// Soal 2: Sorted | |
final mammalSorted = <Animal>[]; | |
animals.sort((x, y) => y.group.compareTo(x.group)); | |
mammalSorted.addAll(animals); | |
// for(var mammal in mammalSorted){ | |
// print('Name is :: ${mammal.name} and Group is ${mammal.group}'); | |
// } | |
// Soal 4: Merge | |
final newAnimals = <Animal>[ | |
Animal(id: 1,name: 'Crocodile', group: 'reptile'), | |
Animal(id: 2,name: 'Eagle', group: 'bird'), | |
Animal(id: 3,name: 'Cat', group: 'mammal'), | |
]; | |
animals.addAll(newAnimals); | |
// for(var mammal in animals){ | |
// print('Name is :: ${mammal.name} and Group is ${mammal.group}'); | |
// } | |
// Soal 5: Timer Delay | |
int n = 5; | |
do { | |
if (n == 0){ | |
print('And close the dor'); | |
}else { | |
print(n); | |
} | |
Future.delayed(Duration(seconds: 1)); | |
n--; | |
}while(n>=0); | |
} | |
class Animal{ | |
int id; | |
String name; | |
String group; | |
Animal({required this.id, required this.name, required this.group}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment