Skip to content

Commit 0c56dbe

Browse files
committed
Integrate copyediting for Chapter 3
1 parent 6f2be22 commit 0c56dbe

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

03_functions.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ functions before they are used.
289289

290290
There's a third notation for functions, which looks very different
291291
from the others. Instead of the `function` keyword, it uses an arrow
292-
(`=>`) made up of equals and greater-than characters (not to be
292+
(`=>`) made up of an equal sign and a greater-than character (not to be
293293
confused with the greater-than-or-equal operator, which is written
294294
`>=`).
295295

@@ -314,7 +314,7 @@ function's body. It expresses something like "this input (the
314314
When there is only one parameter name, you can omit the ((parentheses)) around the
315315
parameter list. If the body is a single expression,
316316
rather than a ((block)) in braces, that expression will be returned
317-
from the function. So these two definitions of `square` do the same
317+
from the function. So, these two definitions of `square` do the same
318318
thing:
319319

320320
```
@@ -333,7 +333,7 @@ const horn = () => {
333333

334334
{{index verbosity}}
335335

336-
There's no very good reason to have both arrow functions and
336+
There's no deep reason to have both arrow functions and
337337
`function` expressions in the language. Apart from a minor detail,
338338
which we'll discuss in [Chapter ?](object), they do the same thing.
339339
Arrow functions were added in 2015, mostly to make it possible to
@@ -443,7 +443,7 @@ accidentally pass the wrong number of arguments to functions. And no
443443
one will tell you about it.
444444

445445
The upside is that this behavior can be used to allow a function to be
446-
called with different amounts of arguments. For example, this `minus`
446+
called with different numbers of arguments. For example, this `minus`
447447
function tries to imitate the `-` operator by acting on either one or
448448
two arguments:
449449

@@ -542,7 +542,7 @@ ways.
542542
{{index "multiplier function"}}
543543

544544
With a slight change, we can turn the previous example into a way to
545-
create functions that multiply by an arbitrary amount:
545+
create functions that multiply by an arbitrary amount.
546546

547547
```
548548
function multiplier(factor) {
@@ -634,8 +634,8 @@ can be paralyzing.
634634

635635
Therefore, always start by writing something that's correct and easy
636636
to understand. If you're worried that it's too slow—which it usually
637-
isn't, since most code simply isn't executed often enough to take any
638-
significant amount of time—you can measure afterwards and improve it
637+
isn't since most code simply isn't executed often enough to take any
638+
significant amount of time—you can measure afterward and improve it
639639
if necessary.
640640

641641
{{index "branching recursion"}}
@@ -650,7 +650,7 @@ into even more branches.
650650
{{index recursion, "number puzzle example"}}
651651

652652
Consider this puzzle: by starting from the number 1 and repeatedly
653-
either adding 5 or multiplying by 3, an infinite amount of new numbers
653+
either adding 5 or multiplying by 3, an infinite set of numbers
654654
can be produced. How would you write a function that, given a number,
655655
tries to find a sequence of such additions and multiplications that
656656
produces that number?
@@ -688,7 +688,7 @@ It is okay if you don't see how it works right away. Let's work
688688
through it, since it makes for a great exercise in recursive thinking.
689689

690690
The inner function `find` does the actual recursing. It takes two
691-
((argument))s: The current number and a string that records how we
691+
((argument))s: the current number and a string that records how we
692692
reached this number. If it finds a solution, it returns a string that
693693
shows how to get to the target. If no solution can be found starting
694694
from this number, it returns `null`.
@@ -700,7 +700,7 @@ number is the target number, the current history is a way to reach
700700
that target, so it is returned. If the current number is greater than
701701
the target, there's no sense in further exploring this branch because
702702
both adding and multiplying will only make the number bigger, so it
703-
returns `null`. And finally, if we're still below the target number,
703+
returns `null`. Finally, if we're still below the target number,
704704
the function tries both possible paths that start from the current
705705
number by calling itself twice, once for addition and once for
706706
multiplication. If the first call returns something that is not
@@ -750,10 +750,10 @@ into programs.
750750

751751
{{index repetition}}
752752

753-
The first is that you find yourself writing very similar code multiple
754-
times. We'd prefer not to do that. Having more code means more space
753+
The first is that you find yourself writing similar code multiple
754+
times. You'd prefer not to do that. Having more code means more space
755755
for mistakes to hide and more material to read for people trying to
756-
understand the program. So we take the repeated functionality, find a
756+
understand the program. So you take the repeated functionality, find a
757757
good name for it, and put it into a function.
758758

759759
The second way is that you find you need some functionality that you
@@ -770,9 +770,9 @@ Let's go through an example.
770770

771771
{{index "farm example"}}
772772

773-
We want to write a program that prints two numbers, the numbers of
773+
We want to write a program that prints two numbers: the numbers of
774774
cows and chickens on a farm, with the words `Cows` and `Chickens`
775-
after them, and zeros padded before both numbers so that they are
775+
after them and zeros padded before both numbers so that they are
776776
always three digits long.
777777

778778
```{lang: null}
@@ -875,7 +875,7 @@ numbers.
875875

876876
How smart and versatile _should_ our function be? We could write
877877
anything, from a terribly simple function that can only pad a number
878-
to be three characters wide, to a complicated generalized
878+
to be three characters wide to a complicated generalized
879879
number-formatting system that handles fractional numbers, negative
880880
numbers, alignment of decimal dots, padding with different characters,
881881
and so on.
@@ -915,7 +915,7 @@ when called with the same arguments, it always produces the same value
915915
(and doesn't do anything else). A call to such a function can be
916916
substituted by its return value without changing the meaning of the
917917
code. When you are not sure that a pure function is working correctly,
918-
you can test it by simply calling it, and know that if it works in
918+
you can test it by simply calling it and know that if it works in
919919
that context, it will work in any context. Nonpure functions tend to
920920
require more scaffolding to test.
921921

@@ -953,7 +953,7 @@ let h = a => a % 3;
953953

954954
A key aspect in understanding functions is understanding scopes. Each
955955
block creates a new scope. Parameters and bindings declared in a given
956-
scope are local, and not visible from the outside. Bindings declared
956+
scope are local and not visible from the outside. Bindings declared
957957
with `var` behave differently—they end up in the nearest function
958958
scope or the global scope.
959959

@@ -1066,7 +1066,7 @@ hint}}
10661066

10671067
You can get the Nth character, or letter, from a string by writing
10681068
`"string"[N]`. The returned value will be a string containing only one
1069-
character (for example, `"b"`). The first character has position zero,
1069+
character (for example, `"b"`). The first character has position 0,
10701070
which causes the last one to be found at position `string.length - 1`.
10711071
In other words, a two-character string has length 2, and its
10721072
characters have positions 0 and 1.

0 commit comments

Comments
 (0)