Skip to content

Commit 578c182

Browse files
committed
Copyediting chapter 4
1 parent 6095635 commit 578c182

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

04_data.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ We could get creative with strings—after all, strings can have any length, so
5454

5555
{{index [array, creation], "[] (array)"}}
5656

57-
Fortunately, JavaScript provides a data type specifically for storing sequences of values. It is called an _array_ and is written as a list of values between ((square brackets)), separated by commas:
57+
Fortunately, JavaScript provides a data type specifically for storing sequences of values. It is called an _array_ and is written as a list of values between ((square brackets)), separated by commas.
5858

5959
```
6060
let listOfNumbers = [2, 3, 5, 7, 11];
@@ -133,7 +133,7 @@ Properties that contain functions are generally called _methods_ of the value th
133133

134134
{{id array_methods}}
135135

136-
This example demonstrates two methods you can use to manipulate arrays:
136+
This example demonstrates two methods you can use to manipulate arrays.
137137

138138
```
139139
let sequence = [1, 2, 3];
@@ -192,7 +192,7 @@ let descriptions = {
192192

193193
{{index [braces, object]}}
194194

195-
This means that braces have _two_ meanings in JavaScript. At the start of a ((statement)), they begin a ((block)) of statements. In any other position, they describe an object. Fortunately, it is rarely useful to start a statement with an object in braces, so the ambiguity between these two is not much of a problem. The one case where this does come up is when you want to return an object from a short-hand arrow function—you can't write `n => {prop: n}` since the braces will be interpreted as a function body. Instead, you have to put a set of parentheses around the object to make it clear that it is an expression.
195+
This means that braces have _two_ meanings in JavaScript. At the start of a ((statement)), they begin a ((block)) of statements. In any other position, they describe an object. Fortunately, it is rarely useful to start a statement with an object in braces, so the ambiguity between these two is not much of a problem. The one case where this does come up is when you want to return an object from a shorthand arrow function—you can't write `n => {prop: n}` since the braces will be interpreted as a function body. Instead, you have to put a set of parentheses around the object to make it clear that it is an expression.
196196

197197
{{index undefined}}
198198

@@ -264,7 +264,7 @@ let journal = [
264264
{events: ["weekend", "cycling", "break", "peanuts",
265265
"beer"],
266266
squirrel: true},
267-
/* and so on... */
267+
/* And so on... */
268268
];
269269
```
270270

@@ -518,7 +518,7 @@ for (let event of journalEvents(JOURNAL)) {
518518
// → weekend: 0.1371988681
519519
// → bread: -0.0757554019
520520
// → pudding: -0.0648203724
521-
// and so on...
521+
// And so on...
522522
```
523523

524524
Most correlations seem to lie close to zero. Eating carrots, bread, or pudding apparently does not trigger squirrel-lycanthropy. The transformations _do_ seem to occur somewhat more often on weekends. Let's filter the results to show only correlations greater than 0.1 or less than -0.1:
@@ -541,7 +541,7 @@ for (let event of journalEvents(JOURNAL)) {
541541

542542
Aha! There are two factors with a ((correlation)) clearly stronger than the others. Eating ((peanuts)) has a strong positive effect on the chance of turning into a squirrel, whereas brushing teeth has a significant negative effect.
543543

544-
Interesting. Let's try something:
544+
Interesting. Let's try something.
545545

546546
```
547547
for (let entry of JOURNAL) {
@@ -560,13 +560,13 @@ Knowing this, Jacques stops eating peanuts altogether and finds that his transfo
560560

561561
{{index "weresquirrel example"}}
562562

563-
But it only takes a few months for him to notice that something is missing from this entirely human way of living. Without his feral adventures, Jacques hardly feels alive at all. He decides he'd rather be a full-time wild animal. After building a beautiful little tree house in the forest and equipping it with a peanut butter dispenser and a ten-year supply of peanut butter, he changes form one last time, and lives the short and energetic life of a squirrel.
563+
But it takes only a few months for him to notice that something is missing from this entirely human way of living. Without his feral adventures, Jacques hardly feels alive at all. He decides he'd rather be a full-time wild animal. After building a beautiful little tree house in the forest and equipping it with a peanut butter dispenser and a ten-year supply of peanut butter, he changes form one last time, and lives the short and energetic life of a squirrel.
564564

565565
## Further arrayology
566566

567567
{{index [array, methods], [method, array]}}
568568

569-
Before finishing the chapter, I want to introduce you to a few more object-related concepts. I'll start by introducing some generally useful array methods.
569+
Before finishing the chapter, I want to introduce you to a few more object-related concepts. I'll start with some generally useful array methods.
570570

571571
{{index "push method", "pop method", "shift method", "unshift method"}}
572572

@@ -745,7 +745,7 @@ When such a function is called, the _((rest parameter))_ is bound to an array co
745745

746746
{{index [function, application]}}
747747

748-
You can use a similar three-dot notation to _call_ a function with an array of arguments:
748+
You can use a similar three-dot notation to _call_ a function with an array of arguments.
749749

750750
```
751751
let numbers = [5, 1, 7];
@@ -797,7 +797,7 @@ Many languages will stop you, or at least warn you, when you are defining a bind
797797

798798
{{index "Math.cos function", "Math.sin function", "Math.tan function", "Math.acos function", "Math.asin function", "Math.atan function", "Math.PI constant", cosine, sine, tangent, "PI constant", pi}}
799799

800-
Back to the `Math` object. If you need to do ((trigonometry)), `Math` can help. It contains `cos` (cosine), `sin` (sine), and `tan` (tangent), as well as their inverse functions, `acos`, `asin`, and `atan`, respectively. The number π (pi)—or at least the closest approximation that fits in a JavaScript number—is available as `Math.PI`. There is an old programming tradition of writing the names of ((constant)) values in all caps:
800+
Back to the `Math` object. If you need to do ((trigonometry)), `Math` can help. It contains `cos` (cosine), `sin` (sine), and `tan` (tangent), as well as their inverse functions, `acos`, `asin`, and `atan`, respectively. The number π (pi)—or at least the closest approximation that fits in a JavaScript number—is available as `Math.PI`. There is an old programming tradition of writing the names of ((constant)) values in all caps.
801801

802802
```{test: no}
803803
function randomPointOnCircle(radius) {
@@ -813,7 +813,7 @@ If you're not familiar with sines and cosines, don't worry. I'll explain them wh
813813

814814
{{index "Math.random function", "random number"}}
815815

816-
The previous example used `Math.random`. This is a function that returns a new pseudorandom number between zero (inclusive) and one (exclusive) every time you call it:
816+
The previous example used `Math.random`. This is a function that returns a new pseudorandom number between 0 (inclusive) and 1 (exclusive) every time you call it:
817817

818818
```{test: no}
819819
console.log(Math.random());
@@ -877,7 +877,7 @@ This also works for bindings created with `let`, `var`, or `const`. If you know
877877

878878
{{index [object, property], [braces, object]}}
879879

880-
A similar trick works for objects, using braces instead of square brackets:
880+
A similar trick works for objects, using braces instead of square brackets.
881881

882882
```
883883
let {name} = {name: "Faraji", age: 23};
@@ -905,7 +905,7 @@ console.log(city({name: "Vera"}));
905905
// → undefined
906906
```
907907

908-
The expression `a?.b` means the same as `a.b` when `a` isn't null or undefined. When it is, it evaluates to undefined. This can be convenient when, as in the example, you aren't sure that a given property exists or when a variable might hold an undefined value.
908+
The expression `a?.b` means the same as `a.b` when `a` isn't null or undefined. When it is, it evaluates to `undefined`. This can be convenient when, as in the example, you aren't sure that a given property exists or when a variable might hold an undefined value.
909909

910910
A similar notation can be used with square bracket access, and even with function calls, by putting `?.` in front of the parentheses or brackets:
911911

@@ -1029,7 +1029,7 @@ hint}}
10291029

10301030
{{index "reversing (exercise)", "reverse method", [array, methods]}}
10311031

1032-
Arrays have a `reverse` method that changes the array by inverting the order in which its elements appear. For this exercise, write two functions, `reverseArray` and `reverseArrayInPlace`. The first, `reverseArray`, should take an array as argument and produce a _new_ array that has the same elements in the inverse order. The second, `reverseArrayInPlace`, should do what the `reverse` method does: _modify_ the array given as argument by reversing its elements. Neither may use the standard `reverse` method.
1032+
Arrays have a `reverse` method that changes the array by inverting the order in which its elements appear. For this exercise, write two functions, `reverseArray` and `reverseArrayInPlace`. The first, `reverseArray`, should take an array as its argument and produce a _new_ array that has the same elements in the inverse order. The second, `reverseArrayInPlace`, should do what the `reverse` method does: _modify_ the array given as its argument by reversing its elements. Neither may use the standard `reverse` method.
10331033

10341034
{{index efficiency, "pure function", "side effect"}}
10351035

@@ -1149,7 +1149,7 @@ hint}}
11491149

11501150
The `==` operator compares objects by identity, but sometimes you'd prefer to compare the values of their actual properties.
11511151

1152-
Write a function `deepEqual` that takes two values and returns true only if they are the same value or are objects with the same properties, where the values of the properties are equal when compared with a recursive call to `deepEqual`.
1152+
Write a function `deepEqual` that takes two values and returns `true` only if they are the same value or are objects with the same properties, where the values of the properties are equal when compared with a recursive call to `deepEqual`.
11531153

11541154
{{index null, "=== operator", "typeof operator"}}
11551155

0 commit comments

Comments
 (0)