Created
October 12, 2023 06:20
-
-
Save abdorll/f799747eb90483c43f8fff96a2a08ee9 to your computer and use it in GitHub Desktop.
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() { | |
getNameTitlesWithNames(childNames).forEach((e){ | |
print("\n${e.letterTitle!}"); | |
print(e.nameList); | |
}); | |
} | |
class EachTitledNameModel{ | |
String? letterTitle; | |
List<String>? nameList=[]; | |
EachTitledNameModel ({this.letterTitle, this.nameList}); | |
} | |
List<EachTitledNameModel> getNameTitlesWithNames(List<String> nameList){ | |
List<EachTitledNameModel> sortedNameWithTitle = []; | |
nameList.sort(); | |
for(int i = 0; i<nameList.length; i++){ | |
String thisTitle= nameList[i][0]; | |
if(sortedNameWithTitle.any((e)=> e.letterTitle== thisTitle)){ | |
continue; | |
} | |
else{ | |
sortedNameWithTitle.add(EachTitledNameModel(letterTitle: thisTitle,nameList: nameList.where((e)=> e[0]==thisTitle).toList())); | |
} | |
} | |
return sortedNameWithTitle; | |
} | |
List<String> childNames = [ | |
"Olivia", | |
"Liam", | |
"Emma", | |
"Noah", | |
"Ava", | |
"Isabella", | |
"Sophia", | |
"Mia", | |
"Charlotte", | |
"Amelia", | |
"Harper", | |
"Evelyn", | |
"Abigail", | |
"Emily", | |
"Elizabeth", | |
"Sofia", | |
"Scarlett", | |
"Grace", | |
"Lily", | |
"Avery", | |
"Ella", | |
"Chloe", | |
"Victoria", | |
"Aria", | |
"Madison", | |
"Layla", | |
"Riley", | |
"Zoe", | |
"Nora", | |
"Lily", | |
"Ethan", | |
"William", | |
"James", | |
"Benjamin", | |
"Henry", | |
"Alexander", | |
"Michael", | |
"Daniel", | |
"Matthew", | |
"Jack", | |
"Samuel", | |
"Joseph", | |
"David", | |
"Andrew", | |
"Noah", | |
"Oliver", | |
"Lucas", | |
"Mason", | |
"Logan", | |
"Caleb", | |
"Elijah", | |
"William", | |
"Gabriel", | |
"Jackson", | |
"Owen", | |
"Joseph", | |
"Aiden", | |
"Sebastian", | |
"Julian", | |
"Wyatt" | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment