Skip to content

Instantly share code, notes, and snippets.

@blacksheep557
Created January 9, 2020 07:48
Show Gist options
  • Select an option

  • Save blacksheep557/cc3ba30ca422f9d007db0b8ab8d012f0 to your computer and use it in GitHub Desktop.

Select an option

Save blacksheep557/cc3ba30ca422f9d007db0b8ab8d012f0 to your computer and use it in GitHub Desktop.
day 62 part 2
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