Skip to content

Commit a3d801c

Browse files
committed
finish 1st batch of code blocks for objects
1 parent 1fe187e commit a3d801c

1 file changed

Lines changed: 66 additions & 3 deletions

File tree

js/data/detailsPreEls.js

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const JavaScript = {
5252
'spread operator'
5353
],
5454
'object': [
55-
'delete',
5655
'hasOwnProperty',
5756
'entries',
5857
'keys',
@@ -488,6 +487,23 @@ function combineObjects(obj1, obj2) {
488487
}
489488
`
490489
},
490+
{
491+
"keywords": ["for in", "hasOwnProperty", "Object.keys", "Object.values", "Object.entries"],
492+
"code": `
493+
const order = { apples: 3, oranges: 5, bananas: 2 };
494+
let total = 0;
495+
496+
for (const key in order) {
497+
if (order.hasOwnProperty(key)) {
498+
total += order[key];
499+
}
500+
}
501+
502+
const keys = Object.keys(order);
503+
const values = Object.values(order);
504+
const entries = Object.entries(order);
505+
`
506+
},
491507
{
492508
"keywords": [""],
493509
"code": ``
@@ -530,7 +546,7 @@ const user = new User("Luna", "luna@email.com", "abc123");
530546
`
531547
},
532548
{
533-
"keywords": [""],
549+
"keywords": [],
534550
"code": ``
535551
},
536552
{
@@ -794,6 +810,20 @@ def combine_dicts(dict1, dict2):
794810
return {**dict1, **dict2}
795811
`
796812
},
813+
{
814+
"keywords": ["for", "keys", "values", "items"],
815+
"code": `
816+
order = {"apples": 3, "oranges": 5, "bananas": 2}
817+
total = 0
818+
819+
for key in order:
820+
total += order[key]
821+
822+
keys = order.keys()
823+
values = order.values()
824+
entries = order.items()
825+
`
826+
},
797827
{
798828
"keywords": [""],
799829
"code": ``
@@ -830,7 +860,7 @@ user = User("Luna", "luna@email.com", "abc123")
830860
`
831861
},
832862
{
833-
"keywords": [""],
863+
"keywords": [],
834864
"code": ``
835865
},
836866
{
@@ -1101,6 +1131,24 @@ rsort($temperatures); // descending
11011131
"code": `
11021132
function combineObjects($obj1, $obj2) {
11031133
return (object) array_merge((array)$obj1, (array)$obj2);
1134+
}
1135+
`
1136+
},
1137+
{
1138+
"keywords": ["foreach", "array_keys", "array_values"],
1139+
"code": `
1140+
$order = ["apples" => 3, "oranges" => 5, "bananas" => 2];
1141+
$total = 0;
1142+
1143+
foreach ($order as $key => $value) {
1144+
$total += $value;
1145+
}
1146+
1147+
$keys = array_keys($order);
1148+
$values = array_values($order);
1149+
$entries = [];
1150+
foreach ($order as $key => $value) {
1151+
$entries[] = [$key, $value];
11041152
}
11051153
`
11061154
},
@@ -1461,6 +1509,21 @@ public static Dictionary<string, object> CombineObjects(
14611509
}
14621510
`
14631511
},
1512+
{
1513+
"keywords": ["foreach", "Keys", "Values", "ToList"],
1514+
"code": `
1515+
var order = new Dictionary<string, int> {{"apples", 3}, {"oranges", 5}, {"bananas", 2}};
1516+
int total = 0;
1517+
1518+
foreach (var kvp in order) {
1519+
total += kvp.Value;
1520+
}
1521+
1522+
var keys = order.Keys;
1523+
var values = order.Values;
1524+
var entries = order.ToList();
1525+
`
1526+
},
14641527
{
14651528
"keywords": [""],
14661529
"code": ``

0 commit comments

Comments
 (0)