Last active
March 5, 2021 23:41
-
-
Save rodion-m/0b4ae5fa4d135030ad10f6647ac176b8 to your computer and use it in GitHub Desktop.
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 numberBook = <String, int>{ | |
"Иван": 2264865, | |
"Татьяна": 89523366684, | |
"Олег": 84952256575, | |
}; | |
numberBook = numberBook.sort((entry1, entry2) => -entry1.key.compareTo(entry2.key)); | |
print(numberBook); | |
} | |
extension MapX<K, V> on Map<K, V> { | |
Map<K, V> sort([int Function(MapEntry<K, V> a, MapEntry<K, V> b)? compare]) { | |
final sortedEntries = entries.toList() | |
..sort(compare); | |
final map = { for (final entry in sortedEntries) entry.key: entry.value }; | |
return map; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment