You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The solution uses`count`in the local variable, but addition methods are written right into the `counter`. They share the same outer lexical environment and also can access the current `count`.
2
+
La solution utilise`count`dans la variable locale, mais les méthodes d'addition sont écrites directement dans le `compteur`. Ils partagent le même environnement lexical extérieur et peuvent également accéder au `count` actuel.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
2
-
1.For the whole thing to work *anyhow*, the result of`sum`must be function.
3
-
2.That function must keep in memory the current value between calls.
4
-
3.According to the task, the function must become the number when used in `==`. Functions are objects, so the conversion happens as described in the chapter<info:object-toprimitive>, and we can provide our own method that returns the number.
2
+
1.Pour que tout fonctionne * de toute façon *, le résultat de`sum`doit être fonction.
3
+
2.Cette fonction doit garder en mémoire la valeur actuelle entre les appels.
4
+
3.Selon la tâche, la fonction doit devenir le numéro lorsqu'elle est utilisée dans `==`. Les fonctions étant des objets, la conversion s'effectue comme décrit dans le chapitre<info:object-toprimitive>, et nous pouvons fournir notre propre méthode qui renvoie le nombre.
Please note that the `sum`function actually works only once. It returns function`f`.
31
+
Veuillez noter que la fonction `sum`ne fonctionne réellement qu'une fois. Il renvoie la fonction`f`.
32
32
33
-
Then, on each subsequent call, `f`adds its parameter to the sum`currentSum`, and returns itself.
33
+
Ensuite, à chaque appel suivant, `f`ajoute son paramètre à la somme`currentSum`, et se renvoie lui-même.
34
34
35
-
**There is no recursion in the last line of`f`.**
35
+
**Il n'y a pas de récursion dans la dernière ligne de`f`.**
36
36
37
-
Here is what recursion looks like:
37
+
Voici à quoi ressemble la récursion:
38
38
39
39
```js
40
40
functionf(b) {
41
41
currentSum += b;
42
-
returnf(); // <-- recursive call
42
+
returnf(); // <-- appel récursif
43
43
}
44
44
```
45
45
46
-
And in our case, we just return the function, without calling it:
46
+
Et dans notre cas, nous renvoyons simplement la fonction, sans l'appeler:
47
47
48
48
```js
49
49
functionf(b) {
50
50
currentSum += b;
51
-
return f; // <-- does not call itself, returns itself
51
+
return f; // <-- ne s'appelle pas, se renvoie
52
52
}
53
53
```
54
54
55
-
This`f`will be used in the next call, again return itself, so many times as needed. Then, when used as a number or a string -- the `toString`returns the`currentSum`. We could also use`Symbol.toPrimitive`or `valueOf`here for the conversion.
55
+
Ce`f`sera utilisé lors du prochain appel et se renvera lui-même autant de fois que nécessaire. Ensuite, lorsqu'il est utilisé sous forme de nombre ou de chaîne, le `toString`renvoie le`currentSum`. Nous pourrions aussi utiliser`Symbol.toPrimitive`ou`valueOf`ici pour la conversion.
0 commit comments