4141{{index "summing example"}}
4242
4343Let'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```
4747let total = 0, count = 1;
@@ -52,7 +52,7 @@ while (count <= 10) {
5252console.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```
5858console.log(sum(range(1, 10)));
@@ -195,7 +195,7 @@ console.log(labels);
195195{{index "loop body", "curly braces"}}
196196
197197This 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
199199as a function value, which is wrapped in the ((parentheses)) of the
200200call to ` repeat ` . This is why it has to be closed with the closing
201201brace _ and_ closing parenthesis. In cases like this example, where the
@@ -282,7 +282,7 @@ Cyrillic, or Arabic.
282282Remember ((Unicode)) from [ Chapter ?] ( values#unicode ) , the system that
283283assigns a number to each character in written language. Most of these
284284characters 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 scripts— 81 are still in use today, and 59
286286are historic.
287287
288288Though 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
327327and upper bound. Any character codes within these ranges are assigned
328328to 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
335335To find the scripts in the data set that are still in use, the
336336following 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```
340340function filter(array, test) {
@@ -425,7 +425,7 @@ number zero and, for each element, add that to the sum.
425425
426426The parameters to ` reduce ` are, apart from the array, a combining
427427function 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```
431431function reduce(array, combine, start) {
@@ -477,13 +477,13 @@ list of the reducer function. The second call to `reduce` then uses
477477this to find the largest script by repeatedly comparing two scripts
478478and 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
481481Unicode standard, making it by far the biggest writing system in the
482482data set. Han is a script (sometimes) used for Chinese, Japanese, and
483483Korean 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
485485decided 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
487487people very angry.
488488
489489## Composability
@@ -605,7 +605,7 @@ But how do we get the character codes in a string?
605605In [ Chapter ?] ( values ) I mentioned that JavaScript ((string))s are
606606encoded as a sequence of 16-bit numbers. These are called _ ((code
607607unit))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
609609characters). When it became clear that wasn't going to be enough, many
610610people balked at the need to use more memory per character. To address
611611these concerns, ((UTF-16)), the format used by JavaScript strings, was
@@ -680,7 +680,7 @@ units), you can use `codePointAt(0)` to get its code.
680680We have a ` characterScript ` function and a way to correctly loop over
681681characters. The next step would be to count the characters that belong
682682to each script. The following counting abstraction will be useful
683- there.
683+ there:
684684
685685``` {includeCode: strip_log}
686686function countBy(items, groupName) {
@@ -751,7 +751,7 @@ To be able to compute ((percentage))s, we first need the total amount
751751of characters that belong to a script, which we can compute with
752752` reduce ` . If no such characters are found, the function returns a
753753specific 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
796796Write a higher-order function ` loop ` that provides something like a
797797` for ` loop statement. It takes a value, a test function, an update
798798function, 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.
800800Then 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
802802starts from the beginning.
803803
804804When 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
859859such an element, we know that all elements matched and we should
860860return 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
864864generalized to arrays, where all elements in the array match if there
865865is 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
880880The 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
883883chapter are probably useful here.
884884
902902
903903Your 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
906906the result that refers to uninteresting (script-less characters).
907907
908908{{index "reduce method"}}
0 commit comments