@@ -652,6 +652,8 @@ The only step remaining is to find a correlation for every type of
652652event that was recorded and see whether anything stands out. How
653653should we store these correlations once we compute them?
654654
655+ {{id for_of_loop}}
656+
655657## Array loops
656658
657659{{index "for loop", loop, [ array, iteration] }}
@@ -682,8 +684,8 @@ for (let entry of journal) {
682684
683685When a ` for ` loops looks like this, with the word ` of ` after a
684686variable definition, it will loop over the elements of the value given
685- after ` of ` . This works not only for arrays, but also for some other
686- data structures. We'll discuss _ how_ it works in [ Chapter
687+ after ` of ` . This works not only for arrays, but also for strings and
688+ some other data structures. We'll discuss _ how_ it works in [ Chapter
6876896] ( 06_object.html ) .
688690
689691## Objects as maps
@@ -812,7 +814,7 @@ for (let event of Object.keys(correlations)) {
812814// and so on...
813815```
814816
815- {{index "for/in loop "}}
817+ {{index "Object.keys function "}}
816818
817819Most correlations seem to lie close to zero. Eating carrots, bread, or
818820pudding apparently does not trigger squirrel-lycanthropy. It _ does_
@@ -1037,7 +1039,7 @@ It can be useful for a function to accept any number of ((argument))s.
10371039For example, ` Math.max ` computes the maximum of _ all_ the arguments it
10381040is given.
10391041
1040- {{indexsee "period character", "max example"}}
1042+ {{indexsee "period character", "max example", spread }}
10411043
10421044To write such a function, you put three dots before the function's
10431045last ((parameter)), like this:
@@ -1059,6 +1061,21 @@ array containing all further arguments. If there are other parameters
10591061before it, their values aren't part of that array. But if it's the
10601062first parameter, as in ` max ` , it will hold all arguments.
10611063
1064+ {{index "function application"}}
1065+
1066+ You can use a similar three-dot notation to _ call_ a function with an
1067+ array of arguments.
1068+
1069+ ```
1070+ let numbers = [5, 1, 7];
1071+ console.log(max(...numbers));
1072+ // → 7
1073+ ```
1074+
1075+ This "((spread))s" out the array into the function call, passing its
1076+ elements as separate arguments. It is possible to include an array
1077+ like that along with other arguments, as in ` max(9, ...numbers, 2) ` .
1078+
10621079## The Math object
10631080
10641081{{index "Math object", "Math.min function", "Math.max function", "Math.sqrt function", minimum, maximum, "square root"}}
@@ -1197,12 +1214,14 @@ function phi([n00, n01, n10, n11]) {
11971214This also works for ((binding))s created with ` let ` , ` var ` , or
11981215` const ` . If you know the value you are binding is an array, you can
11991216use ((square brackets)) to "look inside" of the value, binding its
1200- content.
1217+ content. This works well with ` Object.entries ` , for example.
12011218
12021219```
1203- let [a, b, c] = [1, 2, 3];
1204- console.log(b);
1205- // → 2
1220+ for (let [name, value] in {x: 0, y: 1}) {
1221+ console.log(name, value);
1222+ }
1223+ // → x 0
1224+ // → y 1
12061225```
12071226
12081227{{index object, "curly braces"}}
@@ -1543,11 +1562,11 @@ compare properties only when _both_ arguments are objects. In all
15431562other cases you can just immediately return the result of applying
15441563` === ` .
15451564
1546- {{index "for/in loop ", "in operator"}}
1565+ {{index "Object.keys method ", "in operator"}}
15471566
1548- Use a ` for ` / ` in ` loop to go over the properties. You need to test
1549- whether both objects have the same set of property names and whether
1550- those properties have identical values. The first test can be done by
1567+ Use ` Object.keys ` to go over the properties. You need to test whether
1568+ both objects have the same set of property names and whether those
1569+ properties have identical values. The first test can be done by
15511570counting the properties in both objects and returning false if the
15521571numbers of properties are different. If they're the same, then go over
15531572the properties of one object, and for each of them, verify that the
0 commit comments