@@ -289,7 +289,7 @@ functions before they are used.
289289
290290There's a third notation for functions, which looks very different
291291from 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
293293confused 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
314314When there is only one parameter name, you can omit the ((parentheses)) around the
315315parameter list. If the body is a single expression,
316316rather 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
318318thing:
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,
338338which we'll discuss in [ Chapter ?] ( object ) , they do the same thing.
339339Arrow 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
443443one will tell you about it.
444444
445445The 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 `
447447function tries to imitate the ` - ` operator by acting on either one or
448448two arguments:
449449
@@ -542,7 +542,7 @@ ways.
542542{{index "multiplier function"}}
543543
544544With 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```
548548function multiplier(factor) {
@@ -634,8 +634,8 @@ can be paralyzing.
634634
635635Therefore, always start by writing something that's correct and easy
636636to 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
639639if necessary.
640640
641641{{index "branching recursion"}}
@@ -650,7 +650,7 @@ into even more branches.
650650{{index recursion, "number puzzle example"}}
651651
652652Consider 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
654654can be produced. How would you write a function that, given a number,
655655tries to find a sequence of such additions and multiplications that
656656produces that number?
@@ -688,7 +688,7 @@ It is okay if you don't see how it works right away. Let's work
688688through it, since it makes for a great exercise in recursive thinking.
689689
690690The 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
692692reached this number. If it finds a solution, it returns a string that
693693shows how to get to the target. If no solution can be found starting
694694from this number, it returns ` null ` .
@@ -700,7 +700,7 @@ number is the target number, the current history is a way to reach
700700that target, so it is returned. If the current number is greater than
701701the target, there's no sense in further exploring this branch because
702702both 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,
704704the function tries both possible paths that start from the current
705705number by calling itself twice, once for addition and once for
706706multiplication. 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
755755for 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
757757good name for it, and put it into a function.
758758
759759The 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
774774cows 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
776776always three digits long.
777777
778778``` {lang: null}
@@ -875,7 +875,7 @@ numbers.
875875
876876How smart and versatile _ should_ our function be? We could write
877877anything, 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
879879number-formatting system that handles fractional numbers, negative
880880numbers, alignment of decimal dots, padding with different characters,
881881and 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
916916substituted by its return value without changing the meaning of the
917917code. 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
919919that context, it will work in any context. Nonpure functions tend to
920920require more scaffolding to test.
921921
@@ -953,7 +953,7 @@ let h = a => a % 3;
953953
954954A key aspect in understanding functions is understanding scopes. Each
955955block 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
957957with ` var ` behave differently—they end up in the nearest function
958958scope or the global scope.
959959
@@ -1066,7 +1066,7 @@ hint}}
10661066
10671067You 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 ,
10701070which causes the last one to be found at position ` string.length - 1 ` .
10711071In other words, a two-character string has length 2, and its
10721072characters have positions 0 and 1.
0 commit comments