invert method
Returns a new Map where each entry is inverted, with the key becoming the value and the value becoming the key.
Example:
var map = {'a': 1, 'b': 2, 'c': 3};
map.invert(); // {1: 'a', 2: 'b', 3: 'c'}
As Map does not guarantee an order of iteration over entries, this method does not guarantee which key will be preserved as the value in the case where more than one key is associated with the same value.
Example:
var map = {'a': 1, 'b': 2, 'c': 2};
map.invert(); // May return {1: 'a', 2: 'b'} or {1: 'a', 2: 'c'}.
Implementation
Map<V, K> invert() => Map.fromEntries(
this.entries.map((entry) => MapEntry(entry.value, entry.key)));