Skip to content

Commit 249ad2f

Browse files
committed
sync-06-advanced-functions
1 parent c121c02 commit 249ad2f

96 files changed

Lines changed: 1055 additions & 3111 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1-js/06-advanced-functions/01-recursion/01-sum-to/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ P.S. Naturally, the formula is the fastest solution. It uses only 3 operations f
3737

3838
The loop variant is the second in terms of speed. In both the recursive and the loop variant we sum the same numbers. But the recursion involves nested calls and execution stack management. That also takes resources, so it's slower.
3939

40-
P.P.S. The standard describes a "tail call" optimization: if the recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution and we don't need to remember its execution context. In that case `sumTo(100000)` is countable. But if your JavaScript engine does not support it, there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size.
40+
P.P.S. Some engines support the "tail call" optimization: if a recursive call is the very last one in the function (like in `sumTo` above), then the outer function will not need to resume the execution, so the engine doesn't need to remember its execution context. That removes the burden on memory, so counting `sumTo(100000)` becomes possible. But if the JavaScript engine does not support tail call optimization (most of them don't), there will be an error: maximum stack size exceeded, because there's usually a limitation on the total stack size.
Lines changed: 1 addition & 72 deletions
Loading

1-js/06-advanced-functions/01-recursion/04-output-single-linked-list/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function printList(list) {
4343
}
4444
```
4545

46-
...But that would be unwise. In the future we may need to extend a function, do something else with the list. If we change `list`, then we loose such ability.
46+
...But that would be unwise. In the future we may need to extend a function, do something else with the list. If we change `list`, then we lose such ability.
4747

4848
Talking about good variable names, `list` here is the list itself. The first element of it. And it should remain like that. That's clear and reliable.
4949

1-js/06-advanced-functions/01-recursion/05-output-single-linked-list-reverse/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The loop variant is also a little bit more complicated then the direct output.
3737

3838
There is no way to get the last value in our `list`. We also can't "go back".
3939

40-
So what we can do is to first go through the items in the direct order and rememeber them in an array, and then output what we remembered in the reverse order:
40+
So what we can do is to first go through the items in the direct order and remember them in an array, and then output what we remembered in the reverse order:
4141

4242
```js run
4343
let list = {

0 commit comments

Comments
 (0)