diff --git a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/_js.view/source.js b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/_js.view/source.js index 5bf29aa2d..b293d43e2 100644 --- a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/_js.view/source.js +++ b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/_js.view/source.js @@ -1,7 +1,7 @@ function makeCounter() { let count = 0; - // ... your code ... + // ... votre code ... } let counter = makeCounter(); @@ -9,10 +9,10 @@ let counter = makeCounter(); alert( counter() ); // 0 alert( counter() ); // 1 -counter.set(10); // set the new count +counter.set(10); // définir le nouveau "count" alert( counter() ); // 10 -counter.decrease(); // decrease the count by 1 +counter.decrease(); // diminuer de 1 le "count" -alert( counter() ); // 10 (instead of 11) +alert( counter() ); // 10 (au lieu de 11) diff --git a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md index e829d96ee..77c633e3e 100644 --- a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md +++ b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/solution.md @@ -1,2 +1,2 @@ -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`. +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. diff --git a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md index 0177c8f6e..8f81a7422 100644 --- a/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md +++ b/1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md @@ -2,14 +2,14 @@ importance: 5 --- -# Set and decrease for counter +# Un mutateur et diminution pour counter -Modify the code of `makeCounter()` so that the counter can also decrease and set the number: +Modifiez le code de `makeCounter()` afin que le compteur puisse également diminuer et définir le nombre: -- `counter()` should return the next number (as before). -- `counter.set(value)` should set the `count` to `value`. -- `counter.decrease()` should decrease the `count` by 1. +- `counter()` devrait retourner le nombre suivant (comme avant). +- `counter.set(value)` devrait définir le `count` à être `value`. +- `counter.decrease()` devrait diminuer le `compte` de 1. -See the sandbox code for the complete usage example. +Voir le code sandbox pour un exemple d'utilisation complet. -P.S. You can use either a closure or the function property to keep the current count. Or write both variants. +P.S. Vous pouvez utiliser une fermeture ou la propriété de fonction pour maintenir le nombre actuel. Ou écrivez les deux variantes. diff --git a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md index 5c9326912..7cd6ef3f3 100644 --- a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md +++ b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md @@ -1,9 +1,9 @@ -1. For the whole thing to work *anyhow*, the result of `sum` must be function. -2. That function must keep in memory the current value between calls. -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 , and we can provide our own method that returns the number. +1. Pour que tout fonctionne * de toute façon *, le résultat de `sum` doit être fonction. +2. Cette fonction doit garder en mémoire la valeur actuelle entre les appels. +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 , et nous pouvons fournir notre propre méthode qui renvoie le nombre. -Now the code: +Maintenant le code: ```js run function sum(a) { @@ -28,28 +28,28 @@ alert( sum(6)(-1)(-2)(-3) ); // 0 alert( sum(0)(1)(2)(3)(4)(5) ); // 15 ``` -Please note that the `sum` function actually works only once. It returns function `f`. +Veuillez noter que la fonction `sum` ne fonctionne réellement qu'une fois. Il renvoie la fonction `f`. -Then, on each subsequent call, `f` adds its parameter to the sum `currentSum`, and returns itself. +Ensuite, à chaque appel suivant, `f` ajoute son paramètre à la somme `currentSum`, et se renvoie lui-même. -**There is no recursion in the last line of `f`.** +**Il n'y a pas de récursion dans la dernière ligne de `f`.** -Here is what recursion looks like: +Voici à quoi ressemble la récursion: ```js function f(b) { currentSum += b; - return f(); // <-- recursive call + return f(); // <-- appel récursif } ``` -And in our case, we just return the function, without calling it: +Et dans notre cas, nous renvoyons simplement la fonction, sans l'appeler: ```js function f(b) { currentSum += b; - return f; // <-- does not call itself, returns itself + return f; // <-- ne s'appelle pas, se renvoie } ``` -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. +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. diff --git a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md index dc13f260b..55748fa5d 100644 --- a/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md +++ b/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/task.md @@ -2,9 +2,9 @@ importance: 2 --- -# Sum with an arbitrary amount of brackets +# La somme avec une quantité arbitraire de parenthèses -Write function `sum` that would work like this: +Écrivez la fonction `sum` qui fonctionnerait comme ceci: ```js sum(1)(2) == 3; // 1 + 2 @@ -14,4 +14,4 @@ sum(6)(-1)(-2)(-3) == 0 sum(0)(1)(2)(3)(4)(5) == 15 ``` -P.S. Hint: you may need to setup custom object to primitive conversion for your function. \ No newline at end of file +P.S. Indice: vous devrez peut-être configurer une conversion d'objet à primitive personnalisé pour votre fonction. \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy