Created
January 9, 2020 07:48
-
-
Save blacksheep557/cc3ba30ca422f9d007db0b8ab8d012f0 to your computer and use it in GitHub Desktop.
day 62 part 2
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
| List<List<dynamic>> updateInventory( | |
| List<List<dynamic>> inventoryOne, List<List<dynamic>> inventoryTwo) { | |
| Map<String, int> inventoryMap = {}; | |
| inventoryOne.forEach((List item) { | |
| inventoryMap[item[1]] = item[0]; | |
| }); | |
| inventoryTwo.forEach((List item) { | |
| if (inventoryMap.containsKey(item[1])) { | |
| inventoryMap[item[1]] += item[0]; | |
| } else { | |
| inventoryMap[item[1]] = item[0]; | |
| } | |
| }); | |
| print(inventoryMap); | |
| List<List<dynamic>> output = []; | |
| inventoryMap.forEach((key, value) => output.add([value, key])); | |
| output.sort((List itemOne, List itemTwo) => itemOne[1].compareTo(itemTwo[1])); | |
| print(output); | |
| return output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment