Skip to content

Commit ba3a7fa

Browse files
committed
Integrate editing for Chapter 5
1 parent 7df7e50 commit ba3a7fa

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

05_higher_order.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ find.
4141
{{index "summing example"}}
4242

4343
Let's briefly go back to the final two example programs in the
44-
introduction. The first is self-contained and six lines long.
44+
introduction. The first is self-contained and six lines long:
4545

4646
```
4747
let total = 0, count = 1;
@@ -52,7 +52,7 @@ while (count <= 10) {
5252
console.log(total);
5353
```
5454

55-
The second relies on two external functions and is one line long.
55+
The second relies on two external functions and is one line long:
5656

5757
```
5858
console.log(sum(range(1, 10)));
@@ -195,7 +195,7 @@ console.log(labels);
195195
{{index "loop body", "curly braces"}}
196196

197197
This is structured a little like a `for` loop—it first describes the
198-
kind of loop, and then gives a body. However, the body is now written
198+
kind of loop and then provides a body. However, the body is now written
199199
as a function value, which is wrapped in the ((parentheses)) of the
200200
call to `repeat`. This is why it has to be closed with the closing
201201
brace _and_ closing parenthesis. In cases like this example, where the
@@ -282,7 +282,7 @@ Cyrillic, or Arabic.
282282
Remember ((Unicode)) from [Chapter ?](values#unicode), the system that
283283
assigns a number to each character in written language. Most of these
284284
characters are associated with a specific script. The standard
285-
contains 140 different scripts. 81 of which are still in use today, 59
285+
contains 140 different scripts81 are still in use today, and 59
286286
are historic.
287287

288288
Though I can only fluently read Latin characters, I appreciate the
@@ -326,15 +326,15 @@ The `ranges` property contains an array of Unicode character
326326
((range))s, each of which is a two-element array containing a lower
327327
and upper bound. Any character codes within these ranges are assigned
328328
to the script. The lower ((bound)) is inclusive (code 994 is a Coptic
329-
character) and the upper bound non-inclusive (code 1008 isn't).
329+
character), and the upper bound non-inclusive (code 1008 isn't).
330330

331331
## Filtering arrays
332332

333333
{{index [array, methods], [array, filtering], "filter method", [function, "higher-order"], "predicate function"}}
334334

335335
To find the scripts in the data set that are still in use, the
336336
following function might be helpful. It filters out the elements in an
337-
array that don't pass a test.
337+
array that don't pass a test:
338338

339339
```
340340
function filter(array, test) {
@@ -425,7 +425,7 @@ number zero and, for each element, add that to the sum.
425425

426426
The parameters to `reduce` are, apart from the array, a combining
427427
function and a start value. This function is a little less
428-
straightforward than `filter` and `map`, so look closely.
428+
straightforward than `filter` and `map`, so look closely:
429429

430430
```
431431
function reduce(array, combine, start) {
@@ -477,13 +477,13 @@ list of the reducer function. The second call to `reduce` then uses
477477
this to find the largest script by repeatedly comparing two scripts
478478
and returning the larger one.
479479

480-
The Han script has over 89 thousand characters assigned to it in the
480+
The Han script has over 89,000 characters assigned to it in the
481481
Unicode standard, making it by far the biggest writing system in the
482482
data set. Han is a script (sometimes) used for Chinese, Japanese, and
483483
Korean text. Those languages share a lot of characters, though they
484-
tend to write them differently. The (US based) Unicode Consortium
484+
tend to write them differently. The (US-based) Unicode Consortium
485485
decided to treat them as a single writing system in order to save
486-
character codes. This is called "Han unification" and still makes some
486+
character codes. This is called _Han unification_ and still makes some
487487
people very angry.
488488

489489
## Composability
@@ -605,7 +605,7 @@ But how do we get the character codes in a string?
605605
In [Chapter ?](values) I mentioned that JavaScript ((string))s are
606606
encoded as a sequence of 16-bit numbers. These are called _((code
607607
unit))s_. A ((Unicode)) ((character)) code was initially supposed to
608-
fit within such a unit (which gives you a little over 65 thousand
608+
fit within such a unit (which gives you a little over 65,000
609609
characters). When it became clear that wasn't going to be enough, many
610610
people balked at the need to use more memory per character. To address
611611
these concerns, ((UTF-16)), the format used by JavaScript strings, was
@@ -680,7 +680,7 @@ units), you can use `codePointAt(0)` to get its code.
680680
We have a `characterScript` function and a way to correctly loop over
681681
characters. The next step would be to count the characters that belong
682682
to each script. The following counting abstraction will be useful
683-
there.
683+
there:
684684

685685
```{includeCode: strip_log}
686686
function countBy(items, groupName) {
@@ -751,7 +751,7 @@ To be able to compute ((percentage))s, we first need the total amount
751751
of characters that belong to a script, which we can compute with
752752
`reduce`. If no such characters are found, the function returns a
753753
specific string. Otherwise, it transforms the counting entries into
754-
readable strings with `map`, and then combine them with `join`.
754+
readable strings with `map` and then combines them with `join`.
755755

756756
## Summary
757757

@@ -796,9 +796,9 @@ if}}
796796
Write a higher-order function `loop` that provides something like a
797797
`for` loop statement. It takes a value, a test function, an update
798798
function, and a body function. Each iteration, it first runs the test
799-
function on the current loop value, and stops if that returns false.
799+
function on the current loop value and stops if that returns false.
800800
Then it calls the body function, giving it the current value. And
801-
finally, it calls the update function to create a new value, and
801+
finally, it calls the update function to create a new value and
802802
starts from the beginning.
803803

804804
When defining the function, you can use a regular loop to do the
@@ -859,8 +859,8 @@ function returns false. If the loop runs to its end without finding
859859
such an element, we know that all elements matched and we should
860860
return true.
861861

862-
To build `every` on top of `some`, we can apply "((De Morgan's
863-
laws))", which state that `a && b` equals `!(!a || !b)`. This can be
862+
To build `every` on top of `some`, we can apply _((De Morgan's
863+
laws))_, which state that `a && b` equals `!(!a || !b)`. This can be
864864
generalized to arrays, where all elements in the array match if there
865865
is no element in the array that does not match.
866866

@@ -878,7 +878,7 @@ or `"ttb"` (top-to-bottom).
878878
{{index "characterScript function", "countBy function"}}
879879

880880
The dominant direction is the direction of a majority of the
881-
characters which have a script associated with them. The
881+
characters that have a script associated with them. The
882882
`characterScript` and `countBy` functions defined earlier in the
883883
chapter are probably useful here.
884884

@@ -902,7 +902,7 @@ if}}
902902

903903
Your solution might look a lot like the first half of the
904904
`textScripts` example. You again have to count characters by a
905-
criteria based on `characterScript`, and then filter out the part of
905+
criterion based on `characterScript`, and then filter out the part of
906906
the result that refers to uninteresting (script-less characters).
907907

908908
{{index "reduce method"}}

0 commit comments

Comments
 (0)