From cded230896a9056cf76473d87f2683c6903f5f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Sun, 26 Feb 2023 10:46:47 +0200 Subject: [PATCH 01/16] translated until line 19 --- .../03-closure/article.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index cb43a7968..9512553d0 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -1,22 +1,22 @@ -# Variable scope, closure +# Sfera variabilei, closure -JavaScript is a very function-oriented language. It gives us a lot of freedom. A function can be created at any moment, passed as an argument to another function, and then called from a totally different place of code later. +JavaScript este un limbaj foarte orientat spre funcții. Acesta ne oferă o mare libertate. O funcție poate fi creată în orice moment, transmisă ca argument unei alte funcții, și ulterior apelată dintr-un cu totul alt loc din cod. -We already know that a function can access variables outside of it ("outer" variables). +Știm deja că o funcție poate accesa variabile din afara ei (variabile "exterioare"). -But what happens if outer variables change since a function is created? Will the function get newer values or the old ones? +Dar ce se întâmplă dacă variabilele exterioare se schimbă de la crearea unei funcții? Va primi funcția valorile mai noi sau pe cele vechi? -And what if a function is passed along as an argument and called from another place of code, will it get access to outer variables at the new place? +Și dacă o funcție este transmisă ca argument și apelată dintr-un alt loc din cod, va avea acces la variabilele exterioare din noul loc? -Let's expand our knowledge to understand these scenarios and more complex ones. +Haideți să ne extindem cunoștințele pentru a înțelege aceste scenarii și altele mai complexe. -```smart header="We'll talk about `let/const` variables here" -In JavaScript, there are 3 ways to declare a variable: `let`, `const` (the modern ones), and `var` (the remnant of the past). +```smart header="Vom vorbi despre variabilele `let/const` aici" +În JavaScript, există 3 moduri de a declara o variabilă: `let`, `const` (cele moderne) și `var` (rămășița trecutului). -- In this article we'll use `let` variables in examples. -- Variables, declared with `const`, behave the same, so this article is about `const` too. -- The old `var` has some notable differences, they will be covered in the article . +- În acest articol vom folosi variabilele `let` în exemple. +- Variabilele, declarate cu `const`, se comportă la fel, așa că acest articol se referă și la `const`. +- Vechiul `var` are câteva diferențe notabile, acestea vor fi acoperite în articolul . ``` ## Code blocks From 3b652df531cc07f61396ca19ae79d4bbaf5d28e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Sun, 26 Feb 2023 13:39:55 +0200 Subject: [PATCH 02/16] translated until line 99 --- .../03-closure/article.md | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index 9512553d0..fd5da0e6c 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -19,84 +19,84 @@ Haideți să ne extindem cunoștințele pentru a înțelege aceste scenarii și - Vechiul `var` are câteva diferențe notabile, acestea vor fi acoperite în articolul . ``` -## Code blocks +## Blocuri de cod -If a variable is declared inside a code block `{...}`, it's only visible inside that block. +Dacă o variabilă este declarată în interiorul unui bloc de cod `{...}`, ea este vizibilă doar în interiorul acelui bloc. -For example: +De exemplu: ```js run { - // do some job with local variables that should not be seen outside + // face o treabă cu variabile locale care nu ar trebui să fie văzute în exterior - let message = "Hello"; // only visible in this block + let message = "Salut"; // vizibil doar în acest bloc - alert(message); // Hello + alert(message); // Salut } alert(message); // Error: message is not defined ``` -We can use this to isolate a piece of code that does its own task, with variables that only belong to it: +Putem folosi acest lucru pentru a izola o bucată de cod care își face propria sarcină, cu variabile care îi aparțin doar ei: ```js run { - // show message - let message = "Hello"; + // afișează mesajul + let message = "Salut"; alert(message); } { - // show another message - let message = "Goodbye"; + // afișează un alt mesaj + let message = "La revedere"; alert(message); } ``` -````smart header="There'd be an error without blocks" -Please note, without separate blocks there would be an error, if we use `let` with the existing variable name: +````smart header="Ar exista o eroare fără blocuri" +Vă rugăm să notați că, fără blocuri separate ar exista o eroare, dacă am folosi `let` cu numele variabilei existente: ```js run -// show message -let message = "Hello"; +// arată mesajul +let message = "Salut"; alert(message); -// show another message +// arată un alt mesaj *!* -let message = "Goodbye"; // Error: variable already declared +let message = "La revedere"; // Error: variable already declared */!* alert(message); ``` ```` -For `if`, `for`, `while` and so on, variables declared in `{...}` are also only visible inside: +Pentru `if`, `for`, `while` și așa mai departe, variabilele declarate în `{...}` sunt de asemenea vizibile doar în interior: ```js run if (true) { - let phrase = "Hello!"; + let phrase = "Salut!"; - alert(phrase); // Hello! + alert(phrase); // Salut! } alert(phrase); // Error, no such variable! ``` -Here, after `if` finishes, the `alert` below won't see the `phrase`, hence the error. +Aici, după ce `if` se termină, `alert` de mai jos nu va vedea `phrase`, de unde și eroarea. -That's great, as it allows us to create block-local variables, specific to an `if` branch. +Asta este grozav, deoarece ne permite să creăm variabile locale de bloc, specifice unei ramuri `if`. -The similar thing holds true for `for` and `while` loops: +Același lucru este valabil și pentru buclele `for` și `while`: ```js run for (let i = 0; i < 3; i++) { - // the variable i is only visible inside this for - alert(i); // 0, then 1, then 2 + // variabila i este vizibilă doar în interiorul acestui for + alert(i); // 0, apoi 1, apoi 2 } -alert(i); // Error, no such variable +alert(i); // Eroare, nu există o astfel de variabilă ``` -Visually, `let i` is outside of `{...}`. But the `for` construct is special here: the variable, declared inside it, is considered a part of the block. +Vizual, `let i` se află în afara lui `{...}`. Dar construcția `for` este specială aici: variabila, declarată în interiorul ei, este considerată parte a blocului. ## Nested functions From e3991f5ca8d2a8d7a8c3883ae67de3a289e0803d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Mon, 27 Feb 2023 14:34:24 +0200 Subject: [PATCH 03/16] translated until line 149 --- .../03-closure/article.md | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index fd5da0e6c..352ccd2b7 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -29,9 +29,9 @@ De exemplu: { // face o treabă cu variabile locale care nu ar trebui să fie văzute în exterior - let message = "Salut"; // vizibil doar în acest bloc + let message = "Bună ziua"; // vizibil doar în acest bloc - alert(message); // Salut + alert(message); // Bună ziua } alert(message); // Error: message is not defined @@ -42,7 +42,7 @@ Putem folosi acest lucru pentru a izola o bucată de cod care își face propria ```js run { // afișează mesajul - let message = "Salut"; + let message = "Bună ziua"; alert(message); } @@ -58,7 +58,7 @@ Vă rugăm să notați că, fără blocuri separate ar exista o eroare, dacă am ```js run // arată mesajul -let message = "Salut"; +let message = "Bună ziua"; alert(message); // arată un alt mesaj @@ -73,9 +73,9 @@ Pentru `if`, `for`, `while` și așa mai departe, variabilele declarate în `{.. ```js run if (true) { - let phrase = "Salut!"; + let phrase = "Bună ziua!"; - alert(phrase); // Salut! + alert(phrase); // Bună ziua! } alert(phrase); // Error, no such variable! @@ -98,33 +98,33 @@ alert(i); // Eroare, nu există o astfel de variabilă Vizual, `let i` se află în afara lui `{...}`. Dar construcția `for` este specială aici: variabila, declarată în interiorul ei, este considerată parte a blocului. -## Nested functions +## Funcții nested -A function is called "nested" when it is created inside another function. +O funcție este numită "nested" atunci când este creată în interiorul altei funcții. -It is easily possible to do this with JavaScript. +Acest lucru este posibil cu ușurință în JavaScript. -We can use it to organize our code, like this: +Îl putem folosi pentru a ne organiza codul, astfel: ```js function sayHiBye(firstName, lastName) { - // helper nested function to use below + // funcție helper nested de utilizat mai jos function getFullName() { return firstName + " " + lastName; } - alert( "Hello, " + getFullName() ); - alert( "Bye, " + getFullName() ); + alert( "Bună ziua, " + getFullName() ); + alert( "La revedere, " + getFullName() ); } ``` -Here the *nested* function `getFullName()` is made for convenience. It can access the outer variables and so can return the full name. Nested functions are quite common in JavaScript. +Aici funcția *nested* `getFullName()` este făcută pentru conveniență. Aceasta poate accesa variabilele exterioare și astfel poate returna numele complet. Funcțiile nested sunt destul de frecvente în JavaScript. -What's much more interesting, a nested function can be returned: either as a property of a new object or as a result by itself. It can then be used somewhere else. No matter where, it still has access to the same outer variables. +Ceea ce este mult mai interesant, o funcție nested poate fi returnată: fie ca o proprietate a unui nou obiect ori ca un rezultat de sine stătător. Acesta poate fi apoi utilizat în altă parte. Indiferent unde, aceasta are în continuare acces la aceleași variabile exterioare. -Below, `makeCounter` creates the "counter" function that returns the next number on each invocation: +Mai jos, `makeCounter` creează funcția "counter" care returnează următorul număr la fiecare invocare: ```js run function makeCounter() { @@ -142,11 +142,11 @@ alert( counter() ); // 1 alert( counter() ); // 2 ``` -Despite being simple, slightly modified variants of that code have practical uses, for instance, as a [random number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) to generate random values for automated tests. +În ciuda faptului că sunt simple, variantele ușor modificate ale acestui cod au utilizări practice, de exemplu, ca [generator de numere aleatoare](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) pentru a genera valori aleatoare pentru testele automate. -How does this work? If we create multiple counters, will they be independent? What's going on with the variables here? +Cum funcționează acest lucru? Dacă vom crea mai multe counters, vor fi ele independente? Ce se întâmplă cu variabilele aici? -Understanding such things is great for the overall knowledge of JavaScript and beneficial for more complex scenarios. So let's go a bit in-depth. +Înțelegerea unor astfel de lucruri este excelentă pentru cunoștințele generale despre JavaScript și benefică pentru scenarii mai complexe. Așadar haideți să aprofundăm puțin. ## Lexical Environment From 874f062d3cbe18f500344b73dbf2f136f72dc3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Tue, 28 Feb 2023 12:53:20 +0200 Subject: [PATCH 04/16] translated until line 202 --- .../03-closure/article.md | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index 352ccd2b7..a1adc9897 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -148,58 +148,58 @@ Cum funcționează acest lucru? Dacă vom crea mai multe counters, vor fi ele in Înțelegerea unor astfel de lucruri este excelentă pentru cunoștințele generale despre JavaScript și benefică pentru scenarii mai complexe. Așadar haideți să aprofundăm puțin. -## Lexical Environment +## Mediu Lexical -```warn header="Here be dragons!" -The in-depth technical explanation lies ahead. +```warn header="Aici sunt dragoni!" +Explicația tehnică aprofundată se găsește în cele ce urmează. -As far as I'd like to avoid low-level language details, any understanding without them would be lacking and incomplete, so get ready. +În măsura în care aș dori să evit detaliile low-level ale limbajului, orice înțelegere fără ele ar fi insuficientă și incompletă, așa că pregătiți-vă. ``` -For clarity, the explanation is split into multiple steps. +Pentru claritate, explicația este împărțită în mai mulți pași. -### Step 1. Variables +### Pasul 1. Variabile -In JavaScript, every running function, code block `{...}`, and the script as a whole have an internal (hidden) associated object known as the *Lexical Environment*. +În JavaScript, fiecare funcție care rulează, blocul de cod `{...}`, și scriptul ca întreg au un obiect intern (ascuns) asociat, cunoscut sub numele de *Mediu Lexical*. -The Lexical Environment object consists of two parts: +Obiectul Lexical Environment este constituit din două părți: -1. *Environment Record* -- an object that stores all local variables as its properties (and some other information like the value of `this`). -2. A reference to the *outer lexical environment*, the one associated with the outer code. +1. *Environment Record* -- un obiect care stochează toate variabilele locale ca proprietăți ale acestuia (și alte informații, cum ar fi valoarea lui `this`). +2. O referință la *mediul lexical extern*, cel asociat cu codul extern. -**A "variable" is just a property of the special internal object, `Environment Record`. "To get or change a variable" means "to get or change a property of that object".** +**O "variabilă" este doar o proprietate a obiectului intern special, `Environment Record`. "A obține sau a modifica o variabilă" înseamnă "a obține sau a modifica o proprietate a acelui obiect".** -In this simple code without functions, there is only one Lexical Environment: +În acest cod simplu fără funcții, există un singur Mediu Lexical: ![lexical environment](lexical-environment-global.svg) -This is the so-called *global* Lexical Environment, associated with the whole script. +Acesta este așa-numitul Mediu Lexical *global*, asociat cu întregul script. -On the picture above, the rectangle means Environment Record (variable store) and the arrow means the outer reference. The global Lexical Environment has no outer reference, that's why the arrow points to `null`. +În imaginea de mai sus, dreptunghiul reprezintă Environment Record (stocare de variabile) iar săgeata reprezintă referința exterioară. Mediul Lexical global nu are o referință externă, de aceea săgeata indică `null`. -As the code starts executing and goes on, the Lexical Environment changes. +Pe măsură ce codul începe să se execute și continuă, Mediul Lexical se modifică. -Here's a little bit longer code: +Iată un cod puțin mai lung: -![lexical environment](closure-variable-phrase.svg) +![mediu lexical](closure-variable-phrase.svg) -Rectangles on the right-hand side demonstrate how the global Lexical Environment changes during the execution: +Dreptunghiurile din partea dreaptă demonstrează cum se modifică Mediul Lexical global în timpul execuției: -1. When the script starts, the Lexical Environment is pre-populated with all declared variables. - - Initially, they are in the "Uninitialized" state. That's a special internal state, it means that the engine knows about the variable, but it cannot be referenced until it has been declared with `let`. It's almost the same as if the variable didn't exist. -2. Then `let phrase` definition appears. There's no assignment yet, so its value is `undefined`. We can use the variable from this point forward. -3. `phrase` is assigned a value. -4. `phrase` changes the value. +1. La pornirea scriptului, Mediul Lexical este prepopulat cu toate variabilele declarate. + - Inițial, acestea se află în starea "Uninitialized". Aceasta este o stare internă specială, ceea ce înseamnă că motorul știe despre variabilă, dar nu poate fi referențiată până când nu este declarată cu `let`. Este aproape la fel ca și cum variabila nu ar exista. +2. Apoi apare definiția `let phrase`. Nu există încă o atribuire, deci valoarea ei este `undefined`. Putem folosi variabila din acest punct încolo. +3. Lui `phrase` i se atribuie o valoare. +4. `phrase` își schimbă valoarea. -Everything looks simple for now, right? +Totul pare simplu deocamdată, nu? -- A variable is a property of a special internal object, associated with the currently executing block/function/script. -- Working with variables is actually working with the properties of that object. +- O variabilă este o proprietate a unui obiect intern special, asociată blocului/funcției/scriptului în curs de execuție. +- Lucrul cu variabilele înseamnă de fapt lucrul cu proprietățile acelui obiect. -```smart header="Lexical Environment is a specification object" -"Lexical Environment" is a specification object: it only exists "theoretically" in the [language specification](https://tc39.es/ecma262/#sec-lexical-environments) to describe how things work. We can't get this object in our code and manipulate it directly. +```smart header="Mediul Lexical este un obiect din specificație" +"Mediul Lexical" este un obiect din specificație: el există doar "teoretic" în [specificația limbajului](https://tc39.es/ecma262/#sec-lexical-environments) pentru a descrie modul în care funcționează lucrurile. Nu putem obține acest obiect în codul nostru și să-l manipulăm direct. -JavaScript engines also may optimize it, discard variables that are unused to save memory and perform other internal tricks, as long as the visible behavior remains as described. +De asemenea motoarele JavaScript îl pot optimiza, pot renunța la variabilele nefolosite pentru a economisi memorie și pot efectua alte trucuri interne, atâta timp cât comportamentul vizibil rămâne cel descris. ``` ### Step 2. Function Declarations From 45b35f800b526fff93b4e360c5166f5d3bb68b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Thu, 2 Mar 2023 11:46:32 +0200 Subject: [PATCH 05/16] translated until line 254 --- .../03-closure/article.md | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index a1adc9897..1b602ba3a 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -202,56 +202,56 @@ Totul pare simplu deocamdată, nu? De asemenea motoarele JavaScript îl pot optimiza, pot renunța la variabilele nefolosite pentru a economisi memorie și pot efectua alte trucuri interne, atâta timp cât comportamentul vizibil rămâne cel descris. ``` -### Step 2. Function Declarations +### Pasul 2. Function Declaration -A function is also a value, like a variable. +O funcție este de asemenea o valoare, la fel ca o variabilă. -**The difference is that a Function Declaration is instantly fully initialized.** +**Diferența este că o Function Declaration este instantaneu complet inițializată.** -When a Lexical Environment is created, a Function Declaration immediately becomes a ready-to-use function (unlike `let`, that is unusable till the declaration). +Atunci când este creat un Mediu Lexical, o Function Declaration devine imediat o funcție gata de utilizare (spre deosebire de `let`, care este inutilizabilă până la declarație). -That's why we can use a function, declared as Function Declaration, even before the declaration itself. +De aceea putem utiliza o funcție, declarată ca Function Declaration, chiar înainte de declarația propriu-zisă. -For example, here's the initial state of the global Lexical Environment when we add a function: +De exemplu, iată care este starea inițială a mediului lexical global atunci când adăugăm o funcție: ![](closure-function-declaration.svg) -Naturally, this behavior only applies to Function Declarations, not Function Expressions where we assign a function to a variable, such as `let say = function(name)...`. +Firește, acest comportament se aplică numai la Function Declaration, nu și la Function Expression în care atribuim o funcție unei variabile, cum ar fi `let say = function(name)...`. -### Step 3. Inner and outer Lexical Environment +### Pasul 3. Mediul Lexical interior și exterior -When a function runs, at the beginning of the call, a new Lexical Environment is created automatically to store local variables and parameters of the call. +Atunci când rulează o funcție, la începutul apelului, se creează automat un nou mediu lexical pentru a stoca variabilele locale și parametrii apelului. -For instance, for `say("John")`, it looks like this (the execution is at the line, labelled with an arrow): +De exemplu, pentru `say("John")`, acesta arată astfel (execuția se află la linia marcată cu o săgeată): ![](lexical-environment-simple.svg) -During the function call we have two Lexical Environments: the inner one (for the function call) and the outer one (global): +În timpul apelului funcției avem două medii lexicale: cel intern (pentru apelul funcției) și cel extern (global): -- The inner Lexical Environment corresponds to the current execution of `say`. It has a single property: `name`, the function argument. We called `say("John")`, so the value of the `name` is `"John"`. -- The outer Lexical Environment is the global Lexical Environment. It has the `phrase` variable and the function itself. +- Mediul Lexical intern corespunde execuției curente a lui `say`. Acesta are o singură proprietate: `name`, argumentul funcției. Am apelat `say("John")`, deci valoarea lui `name` este `"John"`. +- Mediul Lexical exterior este Mediul Lexical global. Acesta conține variabila `phrase` și funcția în sine. -The inner Lexical Environment has a reference to the `outer` one. +Mediul Lexical intern are o referință la cel `extern`. -**When the code wants to access a variable -- the inner Lexical Environment is searched first, then the outer one, then the more outer one and so on until the global one.** +**Când codul vrea să acceseze o variabilă -- se caută mai întâi Mediul Lexical interior, apoi cel exterior, apoi cel mai exterior și așa mai departe până la cel global.** -If a variable is not found anywhere, that's an error in strict mode (without `use strict`, an assignment to a non-existing variable creates a new global variable, for compatibility with old code). +Dacă o variabilă nu este găsită nicăieri, este o eroare în modul strict (fără `use strict`, o atribuire la o variabilă inexistentă creează o nouă variabilă globală, pentru compatibilitate cu codul vechi). -In this example the search proceeds as follows: +În acest exemplu căutarea se desfășoară după cum urmează: -- For the `name` variable, the `alert` inside `say` finds it immediately in the inner Lexical Environment. -- When it wants to access `phrase`, then there is no `phrase` locally, so it follows the reference to the outer Lexical Environment and finds it there. +- Pentru variabila `name`, `alert` din `say` o găsește imediat în Mediul Lexical intern. +- Când vrea să acceseze `phrase`, atunci nu există `phrase` la nivel local, așa că urmărește referința la Mediul Lexical exterior și o găsește acolo. ![lexical environment lookup](lexical-environment-simple-lookup.svg) From 6d8df499c824c69df669847b2b02fbad68e163d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Sun, 5 Mar 2023 14:39:50 +0200 Subject: [PATCH 06/16] translated until line 310 --- .../03-closure/article.md | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index 1b602ba3a..aa40a5940 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -98,9 +98,9 @@ alert(i); // Eroare, nu există o astfel de variabilă Vizual, `let i` se află în afara lui `{...}`. Dar construcția `for` este specială aici: variabila, declarată în interiorul ei, este considerată parte a blocului. -## Funcții nested +## Funcții imbricate -O funcție este numită "nested" atunci când este creată în interiorul altei funcții. +O funcție este numită "imbricată" atunci când este creată în interiorul altei funcții. Acest lucru este posibil cu ușurință în JavaScript. @@ -109,7 +109,7 @@ Acest lucru este posibil cu ușurință în JavaScript. ```js function sayHiBye(firstName, lastName) { - // funcție helper nested de utilizat mai jos + // funcție helper imbricată pentru utilizat mai jos function getFullName() { return firstName + " " + lastName; } @@ -120,9 +120,9 @@ function sayHiBye(firstName, lastName) { } ``` -Aici funcția *nested* `getFullName()` este făcută pentru conveniență. Aceasta poate accesa variabilele exterioare și astfel poate returna numele complet. Funcțiile nested sunt destul de frecvente în JavaScript. +Aici funcția *imbricată* `getFullName()` este făcută pentru conveniență. Aceasta poate accesa variabilele exterioare și astfel poate returna numele complet. Funcțiile imbricate sunt destul de frecvente în JavaScript. -Ceea ce este mult mai interesant, o funcție nested poate fi returnată: fie ca o proprietate a unui nou obiect ori ca un rezultat de sine stătător. Acesta poate fi apoi utilizat în altă parte. Indiferent unde, aceasta are în continuare acces la aceleași variabile exterioare. +Ceea ce este mult mai interesant, o funcție imbricată poate fi returnată: fie ca o proprietate a unui nou obiect ori ca un rezultat de sine stătător. Acesta poate fi apoi utilizat în altă parte. Indiferent unde, aceasta are în continuare acces la aceleași variabile exterioare. Mai jos, `makeCounter` creează funcția "counter" care returnează următorul număr la fiecare invocare: @@ -256,9 +256,9 @@ Dacă o variabilă nu este găsită nicăieri, este o eroare în modul strict (f ![lexical environment lookup](lexical-environment-simple-lookup.svg) -### Step 4. Returning a function +### Pasul 4. Returnarea unei funcții -Let's return to the `makeCounter` example. +Să ne întoarcem la exemplul `makeCounter`. ```js function makeCounter() { @@ -272,42 +272,42 @@ function makeCounter() { let counter = makeCounter(); ``` -At the beginning of each `makeCounter()` call, a new Lexical Environment object is created, to store variables for this `makeCounter` run. +La începutul fiecărui apel `makeCounter()`, se creează un nou obiect Lexical Environment, pentru a stoca variabilele pentru această execuție `makeCounter`. -So we have two nested Lexical Environments, just like in the example above: +Astfel avem două Medii Lexicale imbricate, la fel ca în exemplul de mai sus: ![](closure-makecounter.svg) -What's different is that, during the execution of `makeCounter()`, a tiny nested function is created of only one line: `return count++`. We don't run it yet, only create. +Ceea ce este diferit este că, în timpul execuției `makeCounter()`, este creată o mică funcție imbricată de o singură linie: `return count++`. Nu o executăm încă, ci doar o creăm. -All functions remember the Lexical Environment in which they were made. Technically, there's no magic here: all functions have the hidden property named `[[Environment]]`, that keeps the reference to the Lexical Environment where the function was created: +Toate funcțiile își amintesc Mediul Lexical în care au fost create. Tehnic, nu există nici o magie aici: toate funcțiile au o proprietate ascunsă numită `[[Environment]]`, care păstrează referința spre Mediul Lexical în care a fost creată funcția: ![](closure-makecounter-environment.svg) -So, `counter.[[Environment]]` has the reference to `{count: 0}` Lexical Environment. That's how the function remembers where it was created, no matter where it's called. The `[[Environment]]` reference is set once and forever at function creation time. +Astfel, `counter.[[Environment]]` are referință spre Mediul Lexical `{count: 0}`. Așa este cum funcția își amintește unde a fost creată, indiferent unde este apelată. Referința `[[Environment]]` este setată o singură dată și pentru totdeauna la momentul creării funcției. -Later, when `counter()` is called, a new Lexical Environment is created for the call, and its outer Lexical Environment reference is taken from `counter.[[Environment]]`: +Ulterior, când `counter()` este apelat, un nou Mediu Lexical este creat pentru apel, iar referința exterioară a Mediului său Lexical este preluată din `counter.[[Environment]]`: ![](closure-makecounter-nested-call.svg) -Now when the code inside `counter()` looks for `count` variable, it first searches its own Lexical Environment (empty, as there are no local variables there), then the Lexical Environment of the outer `makeCounter()` call, where it finds and changes it. +Acum, atunci când codul din interiorul lui `counter()` caută variabila `count`, caută mai întâi în propriul său Mediu Lexical (gol, deoarece nu există variabile locale acolo), apoi în Mediul Lexical al apelului exterior `makeCounter()`, unde o găsește și o modifică. -**A variable is updated in the Lexical Environment where it lives.** +**O variabilă este actualizată în Mediul Lexical în care trăiește.** -Here's the state after the execution: +Iată care este starea după execuție: ![](closure-makecounter-nested-call-2.svg) -If we call `counter()` multiple times, the `count` variable will be increased to `2`, `3` and so on, at the same place. +Dacă apelăm `counter()` de mai multe ori, variabila `count` va fi mărită la `2`, `3` și așa mai departe, în același loc. ```smart header="Closure" -There is a general programming term "closure", that developers generally should know. +Există un termen general de programare "closure", pe care dezvoltatorii ar trebui în general să-l cunoască. -A [closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)) is a function that remembers its outer variables and can access them. In some languages, that's not possible, or a function should be written in a special way to make it happen. But as explained above, in JavaScript, all functions are naturally closures (there is only one exception, to be covered in ). +Un [closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)) este o funcție care își amintește variabilele exterioare și le poate accesa. În unele limbaje, acest lucru nu este posibil, sau o funcție trebuie scrisă într-un mod special pentru a face acest lucru să se întâmple. Dar așa cum s-a explicat mai sus, în JavaScript, toate funcțiile sunt în mod natural closures (există o singură excepție, care va fi abordată în ). -That is: they automatically remember where they were created using a hidden `[[Environment]]` property, and then their code can access outer variables. +Adică: ele își amintesc automat unde au fost create cu ajutorul unei proprietăți ascunse `[[Environment]]`, iar apoi codul lor poate accesa variabilele exterioare. -When on an interview, a frontend developer gets a question about "what's a closure?", a valid answer would be a definition of the closure and an explanation that all functions in JavaScript are closures, and maybe a few more words about technical details: the `[[Environment]]` property and how Lexical Environments work. +Atunci când, la un interviu, un dezvoltator frontend primește o întrebare despre "ce este un closure?", un răspuns valid ar fi o definiție a closure-ului și o explicație că toate funcțiile din JavaScript sunt closure-uri, și poate câteva cuvinte în plus despre detalii tehnice: proprietatea `[[Environment]]` și cum funcționează Mediile Lexicale. ``` ## Garbage collection From 533707b7c8c257c9aa5bd6415e2ae71e5a425b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Mon, 6 Mar 2023 12:20:12 +0200 Subject: [PATCH 07/16] translated until line 365 --- .../03-closure/article.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index aa40a5940..4fe661b34 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -310,15 +310,15 @@ Adică: ele își amintesc automat unde au fost create cu ajutorul unei propriet Atunci când, la un interviu, un dezvoltator frontend primește o întrebare despre "ce este un closure?", un răspuns valid ar fi o definiție a closure-ului și o explicație că toate funcțiile din JavaScript sunt closure-uri, și poate câteva cuvinte în plus despre detalii tehnice: proprietatea `[[Environment]]` și cum funcționează Mediile Lexicale. ``` -## Garbage collection +## Colectarea gunoiului -Usually, a Lexical Environment is removed from memory with all the variables after the function call finishes. That's because there are no references to it. As any JavaScript object, it's only kept in memory while it's reachable. +De obicei, un Mediu Lexical este eliminat din memorie împreună cu toate variabilele după ce se termină apelul funcției. Acest lucru se datorează faptului că nu mai există referințe la acesta. Ca orice obiect JavaScript, este păstrat în memorie doar atât timp cât este accesibil. -However, if there's a nested function that is still reachable after the end of a function, then it has `[[Environment]]` property that references the lexical environment. +Cu toate acestea, dacă există o funcție imbricată care este încă accesibilă după terminarea unei funcții, atunci aceasta are proprietatea `[[Environment]]` care face referire la Mediul Lexical. -In that case the Lexical Environment is still reachable even after the completion of the function, so it stays alive. +În acel caz Mediul Lexical este încă accesibil chiar și după terminarea funcției, deci rămâne în viață. -For example: +De exemplu: ```js function f() { @@ -329,11 +329,11 @@ function f() { } } -let g = f(); // g.[[Environment]] stores a reference to the Lexical Environment -// of the corresponding f() call +let g = f(); // g.[[Environment]] stochează o referință la Mediul Lexical +// al apelului f() corespunzător ``` -Please note that if `f()` is called many times, and resulting functions are saved, then all corresponding Lexical Environment objects will also be retained in memory. In the code below, all 3 of them: +Vă rugăm să notați că, dacă `f()` este apelat de multe ori, iar funcțiile rezultate sunt salvate, atunci toate obiectele corespunzătoare Mediului Lexical vor fi de asemenea păstrate în memorie. În codul de mai jos, toate cele 3: ```js function f() { @@ -342,14 +342,14 @@ function f() { return function() { alert(value); }; } -// 3 functions in array, every one of them links to Lexical Environment -// from the corresponding f() run +// 3 funcții în matrice, fiecare dintre ele are legătură cu Mediul Lexical +// de la execuția corespunzătoare f() let arr = [f(), f(), f()]; ``` -A Lexical Environment object dies when it becomes unreachable (just like any other object). In other words, it exists only while there's at least one nested function referencing it. +Un obiect Lexical Environment moare atunci când devine inaccesibil (la fel ca orice alt obiect). Cu alte cuvinte, acesta există doar atât timp cât există cel puțin o funcție imbricată care face referire la el. -In the code below, after the nested function is removed, its enclosing Lexical Environment (and hence the `value`) is cleaned from memory: +În codul de mai jos, după ce funcția imbricată este eliminată, Mediul Lexical care o înconjoară (și prin urmare `value`) este curățat din memorie: ```js function f() { @@ -360,9 +360,9 @@ function f() { } } -let g = f(); // while g function exists, the value stays in memory +let g = f(); // cât timp există funcția g, valoarea rămâne în memorie -g = null; // ...and now the memory is cleaned up +g = null; // ...și acum memoria este curățată ``` ### Real-life optimizations From c0150d7690db40697eb0145de00a34e98b7d5df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Tue, 7 Mar 2023 11:33:23 +0200 Subject: [PATCH 08/16] finished translating article --- .../03-closure/article.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/article.md b/1-js/06-advanced-functions/03-closure/article.md index 4fe661b34..d531809c6 100644 --- a/1-js/06-advanced-functions/03-closure/article.md +++ b/1-js/06-advanced-functions/03-closure/article.md @@ -365,24 +365,24 @@ let g = f(); // cât timp există funcția g, valoarea rămâne în memorie g = null; // ...și acum memoria este curățată ``` -### Real-life optimizations +### Optimizări în viața reală -As we've seen, in theory while a function is alive, all outer variables are also retained. +După cum am văzut, în teorie cât timp o funcție este activă, toate variabilele exterioare sunt de asemenea păstrate. -But in practice, JavaScript engines try to optimize that. They analyze variable usage and if it's obvious from the code that an outer variable is not used -- it is removed. +Dar în practică, motoarele JavaScript încearcă să optimizeze acest lucru. Ele analizează utilizarea variabilelor și dacă este evident din cod că o variabilă exterioară nu este utilizată -- aceasta este eliminată. -**An important side effect in V8 (Chrome, Edge, Opera) is that such variable will become unavailable in debugging.** +**Un efect secundar important în V8 (Chrome, Edge, Opera) este că o astfel de variabilă va deveni indisponibilă în depanare.** -Try running the example below in Chrome with the Developer Tools open. +Încercați să rulați exemplul de mai jos în Chrome cu Instrumente de dezvoltare deschise. -When it pauses, in the console type `alert(value)`. +Când se întrerupe, în consolă tastați `alert(value)`. ```js run function f() { let value = Math.random(); function g() { - debugger; // in console: type alert(value); No such variable! + debugger; // în consolă: tastați alert(value); Nu există o astfel de variabilă! } return g; @@ -392,18 +392,18 @@ let g = f(); g(); ``` -As you could see -- there is no such variable! In theory, it should be accessible, but the engine optimized it out. +După cum ați putut vedea -- nu există o astfel de variabilă! În teorie, ar trebui să fie accesibilă, dar motorul a optimizat-o. -That may lead to funny (if not such time-consuming) debugging issues. One of them -- we can see a same-named outer variable instead of the expected one: +Acest lucru poate duce la probleme de depanare amuzante (dacă nu ar fi atât de consumatoare de timp). Una dintre ele -- putem vedea o variabilă exterioară cu același nume în locul celei așteptate: ```js run global -let value = "Surprise!"; +let value = "Surpriză!"; function f() { - let value = "the closest value"; + let value = "cea mai apropiată valoare"; function g() { - debugger; // in console: type alert(value); Surprise! + debugger; // în consolă: tastați alert(value); Surpriză! } return g; @@ -413,6 +413,6 @@ let g = f(); g(); ``` -This feature of V8 is good to know. If you are debugging with Chrome/Edge/Opera, sooner or later you will meet it. +Această caracteristică a V8 este bine de știut. Dacă faceți depanare cu Chrome/Edge/Opera, mai devreme sau mai târziu o veți întâlni. -That is not a bug in the debugger, but rather a special feature of V8. Perhaps it will be changed sometime. You can always check for it by running the examples on this page. +Nu este o eroare a depanatorului, ci mai degrabă o caracteristică specială a V8. Poate că va fi schimbată cândva. Puteți oricând să o verificați rulând exemplele de pe această pagină. From 0519773aac58029c31b9aeedd45480c2db289acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Tue, 7 Mar 2023 11:42:05 +0200 Subject: [PATCH 09/16] translated task 1 --- .../03-closure/1-closure-latest-changes/solution.md | 6 +++--- .../03-closure/1-closure-latest-changes/task.md | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/solution.md b/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/solution.md index 7cbd85ab7..4fdec9c1b 100644 --- a/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/solution.md +++ b/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/solution.md @@ -1,5 +1,5 @@ -The answer is: **Pete**. +Răspunsul este: **Pete**. -A function gets outer variables as they are now, it uses the most recent values. +O funcție primește variabilele exterioare așa cum sunt ele acum, folosește cele mai recente valori. -Old variable values are not saved anywhere. When a function wants a variable, it takes the current value from its own Lexical Environment or the outer one. +Valorile vechi ale variabilelor nu sunt salvate nicăieri. Atunci când o funcție dorește o variabilă, aceasta ia valoarea curentă din propriul mediu lexical sau din cel extern. diff --git a/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/task.md b/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/task.md index 819189773..97c0a6350 100644 --- a/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/task.md +++ b/1-js/06-advanced-functions/03-closure/1-closure-latest-changes/task.md @@ -2,22 +2,22 @@ importance: 5 --- -# Does a function pickup latest changes? +# Preia o funcție ultimele modificări? -The function sayHi uses an external variable name. When the function runs, which value is it going to use? +Funcția sayHi folosește un nume de variabilă externă. Când funcția se execută, ce valoare va folosi? ```js let name = "John"; function sayHi() { - alert("Hi, " + name); + alert("Salut, " + name); } name = "Pete"; -sayHi(); // what will it show: "John" or "Pete"? +sayHi(); // ce va afișa: "John" sau "Pete"? ``` -Such situations are common both in browser and server-side development. A function may be scheduled to execute later than it is created, for instance after a user action or a network request. +Astfel de situații sunt frecvente atât în browser cât și în dezvoltarea pe partea de server. O funcție poate fi programată pentru a fi executată mai târziu decât este creată, de exemplu după o acțiune a utilizatorului sau după o cerere de rețea. -So, the question is: does it pick up the latest changes? +Așadar, întrebarea este: preia cele mai recente modificări? From e54a1c5402f739c365c2dfb736db4b522fcb95a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Tue, 7 Mar 2023 17:54:11 +0200 Subject: [PATCH 10/16] translated task 2 --- .../2-closure-variable-access/solution.md | 8 ++++---- .../03-closure/2-closure-variable-access/task.md | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/2-closure-variable-access/solution.md b/1-js/06-advanced-functions/03-closure/2-closure-variable-access/solution.md index 0a522132f..9cef71595 100644 --- a/1-js/06-advanced-functions/03-closure/2-closure-variable-access/solution.md +++ b/1-js/06-advanced-functions/03-closure/2-closure-variable-access/solution.md @@ -1,9 +1,9 @@ -The answer is: **Pete**. +Răspunsul este: **Pete**. -The `work()` function in the code below gets `name` from the place of its origin through the outer lexical environment reference: +Funcția `work()` din codul de mai jos obține `name` din locul de origine prin intermediul referinței mediului lexical extern: ![](lexenv-nested-work.svg) -So, the result is `"Pete"` here. +Așadar, rezultatul este `"Pete"` aici. -But if there were no `let name` in `makeWorker()`, then the search would go outside and take the global variable as we can see from the chain above. In that case the result would be `"John"`. +Dar dacă nu ar exista `let name` în `makeWorker()`, atunci căutarea ar merge în exterior și ar lua variabila globală, așa cum putem vedea din lanțul de mai sus. În acest caz, rezultatul ar fi `"John"`. diff --git a/1-js/06-advanced-functions/03-closure/2-closure-variable-access/task.md b/1-js/06-advanced-functions/03-closure/2-closure-variable-access/task.md index d12a385c8..571cbf640 100644 --- a/1-js/06-advanced-functions/03-closure/2-closure-variable-access/task.md +++ b/1-js/06-advanced-functions/03-closure/2-closure-variable-access/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Which variables are available? +# Ce variabile sunt disponibile? -The function `makeWorker` below makes another function and returns it. That new function can be called from somewhere else. +Funcția `makeWorker` de mai jos creează o altă funcție și o returnează. Această nouă funcție poate fi apelată din altă parte. -Will it have access to the outer variables from its creation place, or the invocation place, or both? +Va avea acces la variabilele exterioare de la locul de creare, de la locul de invocare, sau ambele? ```js function makeWorker() { @@ -19,11 +19,11 @@ function makeWorker() { let name = "John"; -// create a function +// creați o funcție let work = makeWorker(); -// call it -work(); // what will it show? +// apelați-o +work(); // ce va arăta? ``` -Which value it will show? "Pete" or "John"? +Ce valoare va arăta? "Pete" sau "John"? From 3c3646b0348ab0516003e8d5e98ea9d2db508d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Wed, 8 Mar 2023 20:42:07 +0200 Subject: [PATCH 11/16] task 3 --- .../03-closure/3-counter-independent/solution.md | 6 +++--- .../03-closure/3-counter-independent/task.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/3-counter-independent/solution.md b/1-js/06-advanced-functions/03-closure/3-counter-independent/solution.md index 25ecbea4c..3bd0df525 100644 --- a/1-js/06-advanced-functions/03-closure/3-counter-independent/solution.md +++ b/1-js/06-advanced-functions/03-closure/3-counter-independent/solution.md @@ -1,5 +1,5 @@ -The answer: **0,1.** +Răspunsul: **0,1.** -Functions `counter` and `counter2` are created by different invocations of `makeCounter`. +Funcțiile `counter` și `counter2` sunt create prin invocări diferite ale lui `makeCounter`. -So they have independent outer Lexical Environments, each one has its own `count`. +Deci ele au Medii Lexicale exterioare independente, fiecare având propriul `count`. diff --git a/1-js/06-advanced-functions/03-closure/3-counter-independent/task.md b/1-js/06-advanced-functions/03-closure/3-counter-independent/task.md index e8c17dd31..ed19c24a7 100644 --- a/1-js/06-advanced-functions/03-closure/3-counter-independent/task.md +++ b/1-js/06-advanced-functions/03-closure/3-counter-independent/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Are counters independent? +# Sunt contoarele independente? -Here we make two counters: `counter` and `counter2` using the same `makeCounter` function. +Aici facem două contoare: `counter` și `counter2` folosind aceeași funcție `makeCounter`. -Are they independent? What is the second counter going to show? `0,1` or `2,3` or something else? +Sunt ele independente? Ce va arăta cel de-al doilea contor? `0,1` sau `2,3` sau altceva? ```js function makeCounter() { From 5867d18fa55cd8aa78fd024436a4960983dcaed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Wed, 8 Mar 2023 20:47:31 +0200 Subject: [PATCH 12/16] task 4 --- .../03-closure/4-counter-object-independent/solution.md | 4 ++-- .../03-closure/4-counter-object-independent/task.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/4-counter-object-independent/solution.md b/1-js/06-advanced-functions/03-closure/4-counter-object-independent/solution.md index cd4e641e4..132100069 100644 --- a/1-js/06-advanced-functions/03-closure/4-counter-object-independent/solution.md +++ b/1-js/06-advanced-functions/03-closure/4-counter-object-independent/solution.md @@ -1,7 +1,7 @@ -Surely it will work just fine. +Cu siguranță că va funcționa foarte bine. -Both nested functions are created within the same outer Lexical Environment, so they share access to the same `count` variable: +Ambele funcții imbricate sunt create în cadrul aceluiași Mediu Lexical exterior, astfel încât au acces comun la aceeași variabilă `count`: ```js run function Counter() { diff --git a/1-js/06-advanced-functions/03-closure/4-counter-object-independent/task.md b/1-js/06-advanced-functions/03-closure/4-counter-object-independent/task.md index d770b0ffc..0fd183b0c 100644 --- a/1-js/06-advanced-functions/03-closure/4-counter-object-independent/task.md +++ b/1-js/06-advanced-functions/03-closure/4-counter-object-independent/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Counter object +# Obiect contor -Here a counter object is made with the help of the constructor function. +Aici se creează un obiect contor cu ajutorul funcției constructor. -Will it work? What will it show? +Va funcționa? Ce va arăta? ```js function Counter() { From 85403e9128392313d4d817b0b4ca33d6ad88d59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Fri, 10 Mar 2023 13:03:17 +0200 Subject: [PATCH 13/16] translated tasks 5,6,7 --- .../03-closure/5-function-in-if/solution.md | 4 ++-- .../03-closure/5-function-in-if/task.md | 6 +++--- .../03-closure/6-closure-sum/solution.md | 6 +++--- .../03-closure/6-closure-sum/task.md | 8 ++++---- .../03-closure/7-let-scope/solution.md | 20 +++++++++---------- .../03-closure/7-let-scope/task.md | 6 +++--- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md b/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md index e2e7a91b3..1414c3c72 100644 --- a/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md +++ b/1-js/06-advanced-functions/03-closure/5-function-in-if/solution.md @@ -1,3 +1,3 @@ -The result is **an error**. +Rezultatul este **o eroare**. -The function `sayHi` is declared inside the `if`, so it only lives inside it. There is no `sayHi` outside. \ No newline at end of file +Funcția `sayHi` este declarată în interiorul lui `if`, deci trăiește doar în interiorul acestuia. Nu există `sayHi` în exterior. \ No newline at end of file diff --git a/1-js/06-advanced-functions/03-closure/5-function-in-if/task.md b/1-js/06-advanced-functions/03-closure/5-function-in-if/task.md index 4e386eec5..e0eccd4ce 100644 --- a/1-js/06-advanced-functions/03-closure/5-function-in-if/task.md +++ b/1-js/06-advanced-functions/03-closure/5-function-in-if/task.md @@ -1,12 +1,12 @@ importance: 5 --- -# Function in if +# Funcție în if -Look at the code. What will be the result of the call at the last line? +Priviți codul. Care va fi rezultatul apelului de la ultima linie? ```js run -let phrase = "Hello"; +let phrase = "Bună ziua"; if (true) { let user = "John"; diff --git a/1-js/06-advanced-functions/03-closure/6-closure-sum/solution.md b/1-js/06-advanced-functions/03-closure/6-closure-sum/solution.md index a6679cd20..aaf2ada0a 100644 --- a/1-js/06-advanced-functions/03-closure/6-closure-sum/solution.md +++ b/1-js/06-advanced-functions/03-closure/6-closure-sum/solution.md @@ -1,12 +1,12 @@ -For the second parentheses to work, the first ones must return a function. +Pentru ca a doua paranteză să funcționeze, prima trebuie să returneze o funcție. -Like this: +Astfel: ```js run function sum(a) { return function(b) { - return a + b; // takes "a" from the outer lexical environment + return a + b; // preia "a" din mediul lexical exterior }; } diff --git a/1-js/06-advanced-functions/03-closure/6-closure-sum/task.md b/1-js/06-advanced-functions/03-closure/6-closure-sum/task.md index b45758562..5b45c6182 100644 --- a/1-js/06-advanced-functions/03-closure/6-closure-sum/task.md +++ b/1-js/06-advanced-functions/03-closure/6-closure-sum/task.md @@ -2,13 +2,13 @@ importance: 4 --- -# Sum with closures +# Însumare prin closure -Write function `sum` that works like this: `sum(a)(b) = a+b`. +Scrieți funcția `sum` care funcționează astfel: `sum(a)(b) = a+b`. -Yes, exactly this way, using double parentheses (not a mistype). +Da, exact în acest fel, folosind paranteze duble (nu este o greșeală de scriere). -For instance: +De exemplu: ```js sum(1)(2) = 3 diff --git a/1-js/06-advanced-functions/03-closure/7-let-scope/solution.md b/1-js/06-advanced-functions/03-closure/7-let-scope/solution.md index b16b35290..16ffb2068 100644 --- a/1-js/06-advanced-functions/03-closure/7-let-scope/solution.md +++ b/1-js/06-advanced-functions/03-closure/7-let-scope/solution.md @@ -1,6 +1,6 @@ -The result is: **error**. +Rezultatul este: **eroare**. -Try running it: +Încercați să o rulați: ```js run let x = 1; @@ -15,20 +15,20 @@ function func() { func(); ``` -In this example we can observe the peculiar difference between a "non-existing" and "uninitialized" variable. +În acest exemplu putem observa diferența specifică dintre o variabilă "inexistentă" și una "neinițializată". -As you may have read in the article [](info:closure), a variable starts in the "uninitialized" state from the moment when the execution enters a code block (or a function). And it stays uninitalized until the corresponding `let` statement. +După cum ați putut citi în articolul [](info:closure), o variabilă începe în starea "neinițializată" din momentul în care execuția intră într-un bloc de cod (sau într-o funcție). Și rămâne neinițializată până la instrucțiunea `let` corespunzătoare. -In other words, a variable technically exists, but can't be used before `let`. +Cu alte cuvinte, o variabilă există din punct de vedere tehnic, dar nu poate fi utilizată înainte de `let`. -The code above demonstrates it. +Codul de mai sus demonstrează acest lucru. ```js function func() { *!* - // the local variable x is known to the engine from the beginning of the function, - // but "uninitialized" (unusable) until let ("dead zone") - // hence the error + // variabila locală x este cunoscută de motor din începutul funcției, + // dar "neinițializată" (inutilizabilă) până la let ("zona moartă"). + // de unde și eroarea */!* console.log(x); // ReferenceError: Cannot access 'x' before initialization @@ -37,4 +37,4 @@ function func() { } ``` -This zone of temporary unusability of a variable (from the beginning of the code block till `let`) is sometimes called the "dead zone". +Această zonă de neutilizare temporară a unei variabile (de la începutul blocului de cod până la `let`) se numește uneori "zonă moartă". diff --git a/1-js/06-advanced-functions/03-closure/7-let-scope/task.md b/1-js/06-advanced-functions/03-closure/7-let-scope/task.md index fb7445e66..d202e07be 100644 --- a/1-js/06-advanced-functions/03-closure/7-let-scope/task.md +++ b/1-js/06-advanced-functions/03-closure/7-let-scope/task.md @@ -2,9 +2,9 @@ importance: 4 --- -# Is variable visible? +# Este variabila vizibilă? -What will be the result of this code? +Care va fi rezultatul acestui cod? ```js let x = 1; @@ -18,4 +18,4 @@ function func() { func(); ``` -P.S. There's a pitfall in this task. The solution is not obvious. +P.S. Există o capcană în această sarcină. Soluția nu este evidentă. From 241700b6b933fe2c47c7db5e9002141c6077553f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Sat, 11 Mar 2023 13:57:18 +0200 Subject: [PATCH 14/16] finished translating tasks --- .../03-closure/10-make-army/solution.md | 56 +++++------ .../03-closure/10-make-army/task.md | 26 +++--- .../_js.view/source.js | 4 +- .../8-filter-through-function/task.md | 20 ++-- .../8-make-army/lexenv-makearmy.svg | 93 ------------------- .../9-sort-by-field/_js.view/source.js | 2 +- .../03-closure/9-sort-by-field/task.md | 16 ++-- 7 files changed, 62 insertions(+), 155 deletions(-) delete mode 100644 1-js/06-advanced-functions/03-closure/8-make-army/lexenv-makearmy.svg diff --git a/1-js/06-advanced-functions/03-closure/10-make-army/solution.md b/1-js/06-advanced-functions/03-closure/10-make-army/solution.md index 9d99aa717..503b15ff7 100644 --- a/1-js/06-advanced-functions/03-closure/10-make-army/solution.md +++ b/1-js/06-advanced-functions/03-closure/10-make-army/solution.md @@ -1,14 +1,14 @@ -Let's examine what exactly happens inside `makeArmy`, and the solution will become obvious. +Să examinăm ce se întâmplă mai exact în `makeArmy`, iar soluția va deveni evidentă. -1. It creates an empty array `shooters`: +1. Creează o matrice goală `shooters`: ```js let shooters = []; ``` -2. Fills it with functions via `shooters.push(function)` in the loop. +2. O umple cu funcții prin `shooters.push(function)` în buclă. - Every element is a function, so the resulting array looks like this: + Fiecare element este o funcție, astfel încât matricea rezultată arată astfel: ```js no-beautify shooters = [ @@ -25,40 +25,40 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco ]; ``` -3. The array is returned from the function. +3. Matricea este returnată din funcție. - Then, later, the call to any member, e.g. `army[5]()` will get the element `army[5]` from the array (which is a function) and calls it. + Apoi, mai târziu, apelarea oricărui membru, e.g. `army[5]()` va obține elementul `army[5]` din matrice (care este o funcție) și îl apelează. - Now why do all such functions show the same value, `10`? + Acum de ce toate aceste funcții arată aceeași valoare, `10`? - That's because there's no local variable `i` inside `shooter` functions. When such a function is called, it takes `i` from its outer lexical environment. + Asta pentru că nu există o variabilă locală `i` în interiorul funcțiilor `shooter`. Atunci când o astfel de funcție este apelată, aceasta preia `i` din mediul său lexical exterior. - Then, what will be the value of `i`? + Atunci, care va fi valoarea lui `i`? - If we look at the source: + Dacă ne uităm la sursă: ```js function makeArmy() { ... let i = 0; while (i < 10) { - let shooter = function() { // shooter function - alert( i ); // should show its number + let shooter = function() { // funcția shooter + alert( i ); // ar trebui să arate numărul său }; - shooters.push(shooter); // add function to the array + shooters.push(shooter); // adaugă funcția la matrice i++; } ... } ``` - We can see that all `shooter` functions are created in the lexical environment of `makeArmy()` function. But when `army[5]()` is called, `makeArmy` has already finished its job, and the final value of `i` is `10` (`while` stops at `i=10`). + Putem vedea că toate funcțiile `shooter` sunt create în mediul lexical al funcției `makeArmy()`. Dar când este apelată `army[5]()`, `makeArmy` și-a terminat deja treaba, iar valoarea finală a lui `i` este `10` (`while` se oprește la `i=10`). - As the result, all `shooter` functions get the same value from the outer lexical environment and that is, the last value, `i=10`. + Ca și rezultat, toate funcțiile `shooter` obțin aceeași valoare din mediul lexical extern și anume, ultima valoare, `i=10`. ![](lexenv-makearmy-empty.svg) - As you can see above, on each iteration of a `while {...}` block, a new lexical environment is created. So, to fix this, we can copy the value of `i` into a variable within the `while {...}` block, like this: + După cum puteți vedea mai sus, la fiecare iterație a unui bloc `while {...}`, un nou mediu lexical este creat. Așadar, pentru a remedia acest lucru, putem copia valoarea lui `i` într-o variabilă în cadrul blocului `while {...}`, astfel: ```js run function makeArmy() { @@ -69,8 +69,8 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco *!* let j = i; */!* - let shooter = function() { // shooter function - alert( *!*j*/!* ); // should show its number + let shooter = function() { // funcția shooter + alert( *!*j*/!* ); // ar trebui să arate numărul său }; shooters.push(shooter); i++; @@ -81,18 +81,18 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco let army = makeArmy(); - // Now the code works correctly + // Acum codul funcționează corect army[0](); // 0 army[5](); // 5 ``` - Here `let j = i` declares an "iteration-local" variable `j` and copies `i` into it. Primitives are copied "by value", so we actually get an independent copy of `i`, belonging to the current loop iteration. + Aici `let j = i` declară o variabilă `j` "de iterație locală" și copiază `i` în ea. Primitivele sunt copiate "după valoare", astfel încât obținem de fapt o copie independentă a lui `i`, aparținând iterației curente a buclei. - The shooters work correctly, because the value of `i` now lives a little bit closer. Not in `makeArmy()` Lexical Environment, but in the Lexical Environment that corresponds to the current loop iteration: + Shooters funcționează corect, deoarece valoarea lui `i` trăiește acum un pic mai aproape. Nu în mediul lexical `makeArmy()`, ci în Mediul Lexical care corespunde iterației buclei curente: ![](lexenv-makearmy-while-fixed.svg) - Such a problem could also be avoided if we used `for` in the beginning, like this: + O astfel de problemă ar putea fi evitată și dacă am folosi `for` la început, astfel: ```js run demo function makeArmy() { @@ -102,8 +102,8 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco *!* for(let i = 0; i < 10; i++) { */!* - let shooter = function() { // shooter function - alert( i ); // should show its number + let shooter = function() { // funcția shooter + alert( i ); // ar trebui să arate numărul său }; shooters.push(shooter); } @@ -117,13 +117,13 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco army[5](); // 5 ``` - That's essentially the same, because `for` on each iteration generates a new lexical environment, with its own variable `i`. So `shooter` generated in every iteration references its own `i`, from that very iteration. + În esență, este același lucru, deoarece `for` generează la fiecare iterație un nou mediu lexical, cu propria sa variabilă `i`. Astfel, `shooter` generat în fiecare iterație face referire la propriul `i`, chiar din acea iterație. ![](lexenv-makearmy-for-fixed.svg) -Now, as you've put so much effort into reading this, and the final recipe is so simple - just use `for`, you may wonder -- was it worth that? +Acum, având în vedere că ați depus atât de mult efort pentru a citi acest lucru, iar rețeta finală este atât de simplă - folosiți doar `for`, vă puteți întreba -- s-a meritat? -Well, if you could easily answer the question, you wouldn't read the solution. So, hopefully this task must have helped you to understand things a bit better. +Ei bine, dacă ați putea răspunde cu ușurință la această întrebare, nu ați citi soluția. Așadar, sperăm că această sarcină să vă fi ajutat să înțelegeți un pic mai bine lucrurile. -Besides, there are indeed cases when one prefers `while` to `for`, and other scenarios, where such problems are real. +În rest, există într-adevăr cazuri în care se preferă `while` în locul lui `for`, precum și alte scenarii, în care astfel de probleme sunt reale.S diff --git a/1-js/06-advanced-functions/03-closure/10-make-army/task.md b/1-js/06-advanced-functions/03-closure/10-make-army/task.md index f50c7dc20..90b895387 100644 --- a/1-js/06-advanced-functions/03-closure/10-make-army/task.md +++ b/1-js/06-advanced-functions/03-closure/10-make-army/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Army of functions +# Armata de funcții -The following code creates an array of `shooters`. +Următorul cod creează o matrice de `shooters`. -Every function is meant to output its number. But something is wrong... +Fiecare funcție este menită să emită numărul său. Dar ceva nu este în regulă... ```js run function makeArmy() { @@ -14,28 +14,28 @@ function makeArmy() { let i = 0; while (i < 10) { - let shooter = function() { // create a shooter function, - alert( i ); // that should show its number + let shooter = function() { // crează o funcție shooter, + alert( i ); // care ar trebui să arate numărul său }; - shooters.push(shooter); // and add it to the array + shooters.push(shooter); // și adăugați-l la matrice i++; } - // ...and return the array of shooters + // ...și returnează matricea de shooters return shooters; } let army = makeArmy(); *!* -// all shooters show 10 instead of their numbers 0, 1, 2, 3... -army[0](); // 10 from the shooter number 0 -army[1](); // 10 from the shooter number 1 -army[2](); // 10 ...and so on. +// toți shooters arată 10 în loc de numerele lor 0, 1, 2, 3... +army[0](); // 10 de la shooter cu numărul 0 +army[1](); // 10 de la shooter cu numărul 1 +army[2](); // 10 ...și așa mai departe. */!* ``` -Why do all of the shooters show the same value? +De ce toți shooters arată aceeași valoare? -Fix the code so that they work as intended. +Remediați codul astfel încât acestea să funcționeze așa cum a fost intenționat. diff --git a/1-js/06-advanced-functions/03-closure/8-filter-through-function/_js.view/source.js b/1-js/06-advanced-functions/03-closure/8-filter-through-function/_js.view/source.js index 74989df28..07c94dc40 100644 --- a/1-js/06-advanced-functions/03-closure/8-filter-through-function/_js.view/source.js +++ b/1-js/06-advanced-functions/03-closure/8-filter-through-function/_js.view/source.js @@ -2,9 +2,9 @@ let arr = [1, 2, 3, 4, 5, 6, 7]; function inBetween(a, b) { - // ...your code... + // ...codul tău... } function inArray(arr) { - // ...your code... + // ...codul tău... } diff --git a/1-js/06-advanced-functions/03-closure/8-filter-through-function/task.md b/1-js/06-advanced-functions/03-closure/8-filter-through-function/task.md index d1c39f949..5896fd334 100644 --- a/1-js/06-advanced-functions/03-closure/8-filter-through-function/task.md +++ b/1-js/06-advanced-functions/03-closure/8-filter-through-function/task.md @@ -2,24 +2,24 @@ importance: 5 --- -# Filter through function +# Filtrează printr-o funcție -We have a built-in method `arr.filter(f)` for arrays. It filters all elements through the function `f`. If it returns `true`, then that element is returned in the resulting array. +Avem o metodă încorporată `arr.filter(f)` pentru matrici. Aceasta filtrează toate elementele prin intermediul funcției `f`. Dacă returnează `true`, atunci elementul respectiv este returnat în matricea rezultată. -Make a set of "ready to use" filters: +Creați un set de filtre "gata de utilizare": -- `inBetween(a, b)` -- between `a` and `b` or equal to them (inclusively). -- `inArray([...])` -- in the given array. +- `inBetween(a, b)` -- între `a` și `b` sau egal cu ele (inclusiv). +- `inArray([...])` -- în matricea dată. -The usage must be like this: +Modul de utilizare trebuie să fie următorul: -- `arr.filter(inBetween(3,6))` -- selects only values between 3 and 6. -- `arr.filter(inArray([1,2,3]))` -- selects only elements matching with one of the members of `[1,2,3]`. +- `arr.filter(inBetween(3,6))` -- selectează numai valorile cuprinse între 3 și 6. +- `arr.filter(inArray([1,2,3]))` -- selectează numai elementele care se potrivesc cu unul dintre membrii din `[1,2,3]`. -For instance: +De exemplu: ```js -/* .. your code for inBetween and inArray */ +/* ... codul dvs. pentru inBetween și inArray */ let arr = [1, 2, 3, 4, 5, 6, 7]; alert( arr.filter(inBetween(3, 6)) ); // 3,4,5,6 diff --git a/1-js/06-advanced-functions/03-closure/8-make-army/lexenv-makearmy.svg b/1-js/06-advanced-functions/03-closure/8-make-army/lexenv-makearmy.svg deleted file mode 100644 index aa5e2d6e0..000000000 --- a/1-js/06-advanced-functions/03-closure/8-make-army/lexenv-makearmy.svg +++ /dev/null @@ -1,93 +0,0 @@ - - - - lexenv-makearmy.svg - Created with sketchtool. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - outer - - - - - - - - - i: 0 - - - - - - - - - i: 1 - - - - - - - - - i: 2 - - - - - - - - - i: 10 - - - - ... - - - makeArmy() - Lexical Environment - - - for block - Lexical Environment - - - - \ No newline at end of file diff --git a/1-js/06-advanced-functions/03-closure/9-sort-by-field/_js.view/source.js b/1-js/06-advanced-functions/03-closure/9-sort-by-field/_js.view/source.js index 23b433834..a71d58755 100644 --- a/1-js/06-advanced-functions/03-closure/9-sort-by-field/_js.view/source.js +++ b/1-js/06-advanced-functions/03-closure/9-sort-by-field/_js.view/source.js @@ -1,5 +1,5 @@ function byField(fieldName){ - // Your code goes here. + // Codul tău merge aici. } diff --git a/1-js/06-advanced-functions/03-closure/9-sort-by-field/task.md b/1-js/06-advanced-functions/03-closure/9-sort-by-field/task.md index 08fb5cc34..f2efa5eaa 100644 --- a/1-js/06-advanced-functions/03-closure/9-sort-by-field/task.md +++ b/1-js/06-advanced-functions/03-closure/9-sort-by-field/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# Sort by field +# Sortează după câmp -We've got an array of objects to sort: +Avem o matrice de obiecte de sortat: ```js let users = [ @@ -14,23 +14,23 @@ let users = [ ]; ``` -The usual way to do that would be: +Modul obișnuit de a face acest lucru ar fi: ```js -// by name (Ann, John, Pete) +// după nume (Ann, John, Pete) users.sort((a, b) => a.name > b.name ? 1 : -1); -// by age (Pete, Ann, John) +// după vârstă (Pete, Ann, John) users.sort((a, b) => a.age > b.age ? 1 : -1); ``` -Can we make it even less verbose, like this? +Putem să o facem și mai puțin stufoasă, așa? ```js users.sort(byField('name')); users.sort(byField('age')); ``` -So, instead of writing a function, just put `byField(fieldName)`. +Deci, în loc să scrieți o funcție, puneți doar `byField(fieldName)`. -Write the function `byField` that can be used for that. +Scrieți funcția `byField` care poate fi folosită pentru asta. From 7440355a354d2d7b415d2bc156602e4bd40f099d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Sun, 12 Mar 2023 09:04:07 +0200 Subject: [PATCH 15/16] Deleted unused svg --- .../03-closure/lexenv-nested-work.svg | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 1-js/06-advanced-functions/03-closure/lexenv-nested-work.svg diff --git a/1-js/06-advanced-functions/03-closure/lexenv-nested-work.svg b/1-js/06-advanced-functions/03-closure/lexenv-nested-work.svg deleted file mode 100644 index d8e0b7372..000000000 --- a/1-js/06-advanced-functions/03-closure/lexenv-nested-work.svg +++ /dev/null @@ -1,90 +0,0 @@ - - - - lexenv-nested-work.svg - Created with sketchtool. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - makeWorker: function - name: "John" - - - - - - - - - - - - - - - - - - - <empty> - - - - - - outer - - - - - - outer - - - - - - outer - - - - null - - - - - name: "Pete" - - - - - \ No newline at end of file From 691200a8f868e3466401c0b5b85884d7f91ce2aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20Baco=C8=99c=C4=83?= Date: Sun, 12 Mar 2023 09:35:48 +0200 Subject: [PATCH 16/16] minor update --- .../03-closure/10-make-army/_js.view/solution.js | 4 ++-- .../03-closure/10-make-army/_js.view/source.js | 10 +++++----- .../03-closure/10-make-army/_js.view/test.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/solution.js b/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/solution.js index a26578ae1..bcca85b10 100644 --- a/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/solution.js +++ b/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/solution.js @@ -3,8 +3,8 @@ function makeArmy() { let shooters = []; for(let i = 0; i < 10; i++) { - let shooter = function() { // shooter function - alert( i ); // should show its number + let shooter = function() { // funcția shooter + alert( i ); // ar trebui să arate numărul său }; shooters.push(shooter); } diff --git a/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/source.js b/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/source.js index 7c7aaa1e3..6d687aba9 100644 --- a/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/source.js +++ b/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/source.js @@ -3,8 +3,8 @@ function makeArmy() { let i = 0; while (i < 10) { - let shooter = function() { // shooter function - alert( i ); // should show its number + let shooter = function() { // funcția shooter + alert( i ); // ar trebui să arate numărul său }; shooters.push(shooter); i++; @@ -16,7 +16,7 @@ function makeArmy() { /* let army = makeArmy(); -army[0](); // the shooter number 0 shows 10 -army[5](); // and number 5 also outputs 10... -// ... all shooters show 10 instead of their 0, 1, 2, 3... +army[0](); // numărul shooter 0 arată 10 +army[5](); // și numărul 5 de asemeni produce 10... +// ... toți shooters arată 10 în loc de 0, 1, 2, 3... */ diff --git a/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/test.js b/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/test.js index b61e6e4db..cf2ec4783 100644 --- a/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/test.js +++ b/1-js/06-advanced-functions/03-closure/10-make-army/_js.view/test.js @@ -7,13 +7,13 @@ describe("army", function() { window.alert = sinon.stub(window, "alert"); }); - it("army[0] shows 0", function() { + it("army[0] arată 0", function() { army[0](); assert(alert.calledWith(0)); }); - it("army[5] shows 5", function() { + it("army[5] arată 5", function() { army[5](); assert(alert.calledWith(5)); });