Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cadaguman Maps and Sets #19

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
void main() {
const order = ['margherita', 'pepperoni', 'pineapple'];
final total = calculateTotal(order);
print('Total: \$$total');
}

double calculateTotal(List<String> order) {
const pizzaPrices = {
'margherita': 5.5,
'pepperoni': 7.5,
'vegetarian': 6.5,
};
var total = 0.0;
for (var item in order) {
final price = pizzaPrices[item];
if (price != null) {
total += price;
}
}
return total;
}
20 changes: 20 additions & 0 deletions sets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void main() {
var a = <int>{1, 3};
var b = <int>{3, 5};

var intersection = a.intersection(b);

var union = a.union(b);

var unionWithoutIntersection = union.difference(intersection);

print(unionWithoutIntersection);

var sum = 0;

for (var i = 0; i < unionWithoutIntersection.length; i++) {
sum += unionWithoutIntersection.elementAt(i);
}

print(sum);
}