@@ -20,7 +20,7 @@ quote}}
2020Numbers, Booleans, and strings are the atoms that ((data)) structures
2121are built from. Many types of information require more than one
2222atom, though. _ Objects_ allow us to group values—including other
23- objects—together to build more complex structures.
23+ objects—to build more complex structures.
2424
2525The programs we have built so far have been limited by the fact that
2626they were operating only on simple data types. This chapter will
4747
4848{{index "weresquirrel example", lycanthropy}}
4949
50- Every now and then, usually between eight and ten in the evening ,
50+ Every now and then, usually between 8 p.m. and 10 p.m. ,
5151((Jacques)) finds himself transforming into a small furry rodent with
5252a bushy tail.
5353
@@ -121,7 +121,7 @@ _((index))_ given by the expression in the brackets.
121121
122122The first index of an array is zero, not one. So the first element is
123123retrieved with ` listOfNumbers[0] ` . Zero-based counting has a long
124- tradition in technology, and in certain ways makes a lot of sense, but
124+ tradition in technology and in certain ways makes a lot of sense, but
125125it takes some getting used to. Think of the index as the amount of
126126items to skip, counting from the start of the array.
127127
@@ -173,7 +173,7 @@ property named _2_ or _John Doe_, you must use square brackets:
173173
174174The elements in an ((array)) are stored as the array's properties, using
175175numbers as property names. Because you can't use the dot notation with
176- numbers, and usually want to use a binding that holds the index
176+ numbers and usually want to use a binding that holds the index
177177anyway, you have to use the bracket notation to get at them.
178178
179179{{index [ "length property", "for array"] , [ array, "length of"] }}
@@ -214,7 +214,7 @@ value whose property we called. How this works is described in
214214[ Chapter ?] ( object#obj_methods ) .
215215
216216Properties that contain functions are generally called _ methods_ of
217- the value they belong to. As in, "` toUpperCase ` is a method of a
217+ the value they belong to, as in "` toUpperCase ` is a method of a
218218string".
219219
220220{{id array_methods}}
@@ -243,7 +243,7 @@ and returning it.
243243These somewhat silly names are the traditional terms for operations on
244244a _ ((stack))_ . A stack, in programming, is a ((data structure)) that
245245allows you to push values into it and pop them out again in the
246- opposite order, so that the thing that was added last is removed first.
246+ opposite order so that the thing that was added last is removed first.
247247These are common in programming—you might remember the function ((call
248248stack)) from [ the previous chapter] ( functions#stack ) , which is an
249249instance of the same idea.
@@ -297,7 +297,7 @@ let descriptions = {
297297This means that ((braces)) have _ two_ meanings in JavaScript. At
298298the start of a ((statement)), they start a ((block)) of statements. In
299299any other position, they describe an object. Fortunately, it is rarely
300- useful to start a statement with a curly-brace object, so the
300+ useful to start a statement with an object in braces , so the
301301ambiguity between these two is not much of a problem.
302302
303303{{index undefined}}
@@ -467,7 +467,7 @@ score = {visitors: 1, home: 1};
467467{{index "== operator", [ comparison, "of objects"] , "deep comparison"}}
468468
469469When you compare objects with JavaScript's ` == ` operator, it compares
470- by identity: It will produce ` true ` only if both objects are precisely
470+ by identity: it will produce ` true ` only if both objects are precisely
471471the same value. Comparing different objects will return ` false ` , even
472472if they have identical properties. There is no "deep" comparison
473473operation built into JavaScript, which compares objects by contents,
@@ -478,7 +478,7 @@ but it is possible to write it yourself (which is one of the
478478
479479{{index "weresquirrel example", lycanthropy, "addEntry function"}}
480480
481- So Jacques starts up his JavaScript interpreter and sets up the
481+ So, Jacques starts up his JavaScript interpreter and sets up the
482482environment he needs to keep his ((journal)).
483483
484484``` {includeCode: true}
@@ -493,11 +493,11 @@ function addEntry(events, squirrel) {
493493
494494Note that the object added to the journal looks a little odd. Instead
495495of declaring properties like ` events: events ` , it just gives a
496- ((property)) name. This is a short-hand that means the same thing—if a
497- property name in curly brace notation isn't followed by a value, its
496+ ((property)) name. This is shorthand that means the same thing—if a
497+ property name in brace notation isn't followed by a value, its
498498value is taken from the binding with the same name.
499499
500- So then, every evening at ten —or sometimes the next morning, after
500+ So then, every evening at 10 p.m. —or sometimes the next morning, after
501501climbing down from the top shelf of his bookcase—Jacques records the
502502day.
503503
@@ -530,7 +530,7 @@ opposites—when one is true, the other is false.
530530
531531To compute the measure of correlation between two Boolean variables,
532532we can use the _ phi coefficient_ (_ ϕ_ ). This is a formula whose input
533- is a ((frequency table)) containing the amount of times the different
533+ is a ((frequency table)) containing the number of times the different
534534combinations of the variables were observed. The output of the formula
535535is a number between -1 and 1 that describes the correlation.
536536
567567
568568(If at this point you're putting the book down to focus on a terrible
569569flashback to 10th grade math class—hold on! I do not intend to torture
570- you with endless pages of cryptic notation—just this one formula for
570+ you with endless pages of cryptic notation—it's just this one formula for
571571now. And even with this one, all we do is turn it into JavaScript.)
572572
573573The notation [ _ n_ ~ 01~ ] {if html}[[ $n_ {01}$] {latex}] {if tex} indicates
@@ -643,7 +643,7 @@ Jacques kept his journal for three months. The resulting ((data set))
643643is available in the [ coding
644644sandbox] ( https://eloquentjavascript.net/code#4 ) for this chapter[
645645([ _ https://eloquentjavascript.net/code#4 _ ] ( https://eloquentjavascript.net/code#4 ) )] {if
646- book}, where it is stored in the ` JOURNAL ` binding, and in a
646+ book}, where it is stored in the ` JOURNAL ` binding and in a
647647downloadable
648648[ file] ( https://eloquentjavascript.net/code/journal.js ) .
649649
@@ -720,7 +720,7 @@ for (let entry of JOURNAL) {
720720
721721When a ` for ` loop looks like this, with the word ` of ` after a variable
722722definition, it will loop over the elements of the value given after
723- ` of ` . This works not only for arrays, but also for strings and some
723+ ` of ` . This works not only for arrays but also for strings and some
724724other data structures. We'll discuss _ how_ it works in [ Chapter
725725?] ( object ) .
726726
@@ -753,7 +753,7 @@ console.log(journalEvents(JOURNAL));
753753// → ["carrot", "exercise", "weekend", "bread", …]
754754```
755755
756- By going over all the events, and adding those that aren't already in
756+ By going over all the events and adding those that aren't already in
757757there to the ` events ` array, the function collects every type of
758758event.
759759
@@ -792,7 +792,7 @@ for (let event of journalEvents(JOURNAL)) {
792792// → peanuts: 0.5902679812
793793```
794794
795- A-ha ! There are two factors with a ((correlation)) that's clearly stronger
795+ Aha ! There are two factors with a ((correlation)) that's clearly stronger
796796than the others. Eating ((peanuts)) has a strong positive effect on
797797the chance of turning into a squirrel, whereas brushing his teeth has
798798a significant negative effect.
@@ -868,7 +868,7 @@ adds it to the front instead of the back of the queue.
868868
869869{{index [ array, searching] , "indexOf method", "lastIndexOf method"}}
870870
871- To search for a specific value, arrays provide an ` indexOf ` method. It
871+ To search for a specific value, arrays provide an ` indexOf ` method. The method
872872searches through the array from the start to the end and returns the
873873index at which the requested value was found—or -1 if it wasn't found.
874874To search from the end instead of the start, there's a similar method
@@ -910,7 +910,7 @@ new array, similar to what the `+` operator does for strings.
910910
911911The following example shows both ` concat ` and ` slice ` in action. It takes
912912an array and an index, and it returns a new array that is a copy of
913- the original array with the element at the given index removed:
913+ the original array with the element at the given index removed.
914914
915915```
916916function remove(array, index) {
@@ -940,7 +940,7 @@ console.log(kim.age);
940940
941941Values of type string, number, and Boolean are not objects, and though
942942the language doesn't complain if you try to set new properties on
943- them, it doesn't actually store those properties. As mentioned before ,
943+ them, it doesn't actually store those properties. As mentioned earlier ,
944944such values are immutable and cannot be changed.
945945
946946{{index [ string, methods] , "slice method", "indexOf method", [ string, searching] }}
@@ -987,7 +987,7 @@ console.log(String(6).padStart(3, "0"));
987987{{id split}}
988988
989989You can split a string on every occurrence of another string with
990- ` split ` , and join it together again with ` join ` .
990+ ` split ` and join it again with ` join ` .
991991
992992```
993993let sentence = "Secretarybirds specialize in stomping";
@@ -1074,7 +1074,7 @@ like that along with other arguments, as in `max(9, ...numbers, 2)`.
10741074{{index array, "square brackets"}}
10751075
10761076Square bracket array notation similarly allows the triple-dot operator
1077- to spread another array into the new array:
1077+ to spread another array into the new array.
10781078
10791079```
10801080let words = ["never", "fully"];
@@ -1086,7 +1086,7 @@ console.log(["will", ...words, "understand"]);
10861086
10871087{{index "Math object", "Math.min function", "Math.max function", "Math.sqrt function", minimum, maximum, "square root"}}
10881088
1089- As we've seen, ` Math ` is a grab- bag of number-related utility
1089+ As we've seen, ` Math ` is a grab bag of number-related utility
10901090functions, such as ` Math.max ` (maximum), ` Math.min ` (minimum), and
10911091` Math.sqrt ` (square root).
10921092
@@ -1113,7 +1113,7 @@ Since JavaScript's built-in `max` function is tucked safely inside the
11131113Many languages will stop you, or at least warn you, when you are
11141114defining a binding with a name that is already taken. JavaScript does
11151115this for bindings you declared with ` let ` or ` const `
1116- but—perversely—not for standard bindings, nor for bindings declared
1116+ but—perversely—not for standard bindings nor for bindings declared
11171117with ` var ` or ` function ` .
11181118
11191119{{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}}
@@ -1178,7 +1178,7 @@ console.log(Math.floor(Math.random() * 10));
11781178```
11791179
11801180Multiplying the random number by 10 gives us a number greater than or
1181- equal to zero and below 10. Since ` Math.floor ` rounds down, this
1181+ equal to 0 and below 10. Since ` Math.floor ` rounds down, this
11821182expression will produce, with equal chance, any number from 0 through
118311839 .
11841184
@@ -1193,7 +1193,7 @@ negates negative values but leaves positive ones as they are.
11931193
11941194{{index "phi function"}}
11951195
1196- Let's go back to the ` phi ` function for a moment:
1196+ Let's go back to the ` phi ` function for a moment.
11971197
11981198``` {test: wrap}
11991199function phi(table) {
@@ -1256,7 +1256,7 @@ of (at least) one memory region for the inner array, and another for
12561256the outer array, containing (among other things) a binary number that
12571257represents the position of the inner array.
12581258
1259- If you want to save data in a file for later, or send it to another
1259+ If you want to save data in a file for later or send it to another
12601260computer over the network, you have to somehow convert these tangles
12611261of memory addresses to a description that can be stored or sent. You
12621262_ could_ send over your entire computer memory along with the address
@@ -1402,7 +1402,7 @@ by writing two separate loops—one for counting up and one for counting
14021402down—because the comparison that checks whether the loop is finished
14031403needs to be ` >= ` rather than ` <= ` when counting downward.
14041404
1405- It might also be worthwhile to use a different default step, namely
1405+ It might also be worthwhile to use a different default step, namely,
14061406-1, when the end of the range is smaller than the start. That way,
14071407` range(5, 2) ` returns something meaningful, rather than getting stuck
14081408in an ((infinite loop)). It is possible to refer to previous
@@ -1414,7 +1414,7 @@ hint}}
14141414
14151415{{index "reversing (exercise)", "reverse method", [ array, methods] }}
14161416
1417- Arrays have a ` reverse ` method which changes the array by inverting
1417+ Arrays have a ` reverse ` method that changes the array by inverting
14181418the order in which its elements appear. For this exercise, write two
14191419functions, ` reverseArray ` and ` reverseArrayInPlace ` . The first,
14201420` reverseArray ` , takes an array as argument and produces a _ new_ array
@@ -1547,7 +1547,7 @@ if}}
15471547{{index "list (exercise)", "linked list"}}
15481548
15491549Building up a list is easier when done back to front. So ` arrayToList `
1550- could iterate over the array backwards (see previous exercise) and, for
1550+ could iterate over the array backwards (see the previous exercise) and, for
15511551each element, add an object to the list. You can use a local binding
15521552to hold the part of the list that was built so far and use an
15531553assignment like ` list = {value: X, rest: list} ` to add an element.
@@ -1565,14 +1565,14 @@ Can you see how that works? Every iteration of the loop, `node` points
15651565to the current sublist, and the body can read its ` value ` property to
15661566get the current element. At the end of an iteration, ` node ` moves to
15671567the next sublist. When that is null, we have reached the end of the
1568- list and the loop is finished.
1568+ list, and the loop is finished.
15691569
15701570{{index recursion}}
15711571
15721572The recursive version of ` nth ` will, similarly, look at an ever
15731573smaller part of the "tail" of the list and at the same time count down
15741574the index until it reaches zero, at which point it can return the
1575- ` value ` property of the node it is looking at. To get the zeroeth
1575+ ` value ` property of the node it is looking at. To get the zeroth
15761576element of a list, you simply take the ` value ` property of its head
15771577node. To get element _ N_ + 1, you take the _ N_th element of the list
15781578that's in this list's ` rest ` property.
@@ -1640,9 +1640,9 @@ both objects have the same set of property names and whether those
16401640properties have identical values. One way to do that is to ensure that
16411641both objects have the same number of properties (the lengths of the
16421642property lists are the same). And then, when looping over one of the
1643- object's properties in order to compare them, always first make sure
1643+ object's properties to compare them, always first make sure
16441644the other actually has a property by that name. If they have the same
1645- number of properties, and all properties in one also exist in the
1645+ number of properties and all properties in one also exist in the
16461646other, they have the same set of property names.
16471647
16481648{{index "return value"}}
0 commit comments