Skip to content

Commit 3049652

Browse files
authored
Merge pull request #230 from Dorin-David/Array-methods
array methods review
2 parents 7acc02b + 28e1a56 commit 3049652

File tree

23 files changed

+136
-130
lines changed

23 files changed

+136
-130
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function camelize(str) {
22
return str
3-
.split('-') // splits 'my-long-word' into array ['my', 'long', 'word']
3+
.split('-') // divide 'my-long-word' in un array ['my', 'long', 'word']
44
.map(
5-
// capitalizes first letters of all array items except the first one
6-
// converts ['my', 'long', 'word'] into ['my', 'Long', 'Word']
5+
// rende maiuscole le prime lettere di tutti gli elementi dell'array eccetto il primo
6+
// trasforma ['my', 'long', 'word'] in ['my', 'Long', 'Word']
77
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)
88
)
9-
.join(''); // joins ['my', 'Long', 'Word'] into 'myLongWord'
9+
.join(''); // unisce ['my', 'Long', 'Word'] in 'myLongWord'
1010
}

1-js/05-data-types/05-array-methods/1-camelcase/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ importance: 5
44

55
# Traducete border-left-width in borderLeftWidth
66

7-
Scrivete una funzione `camelize(str)` che cambia trasforma le parole seprate da trattino come "la-mia-stringa", nella notazione a cammello "laMiaStringa".
7+
Scrivete una funzione `camelize(str)` che trasforma le parole separate da un trattino come "la-mia-stringa" nella notazione a cammello "laMiaStringa".
88

9-
Quindi: rimuove tutti i trattini, ogni parola dopo un trattino diventerà con una lettera maiuscola.
9+
Quindi: rimuove tutti i trattini; ogni parola dopo un trattino avrà una lettera maiuscola.
1010

1111
Esempi:
1212

@@ -16,4 +16,4 @@ camelize("list-style-image") == 'listStyleImage';
1616
camelize("-webkit-transition") == 'WebkitTransition';
1717
```
1818

19-
P.S. Suggerimento: usate `split` per divider una stringa in array, trasformatela e infinite riunite tutto con `join`.
19+
P.S. Suggerimento: usate `split` per dividere una stringa in un array, trasformatela e infinite riunite tutto con `join`.

1-js/05-data-types/05-array-methods/10-average-age/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 4
44

55
# Ottenere l'età media+
66

7-
Scrivete una funzione `getAverageAge(users)` che prende un array di oggetti con la proprietà `age` e ritorni l'età media.
7+
Scrivete una funzione `getAverageAge(users)` che accetti un array di oggetti con la proprietà `age` e ritorni l'età media.
88

99
La formula della media è: `(age1 + age2 + ... + ageN) / N`.
1010

1-js/05-data-types/05-array-methods/11-array-unique/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ let strings = ["Hare", "Krishna", "Hare", "Krishna",
2222
alert( unique(strings) ); // Hare, Krishna, :-O
2323
```
2424

25-
Il codice funziona, ma c'è un potenziale problmea di performace.
25+
Il codice funziona, ma c'è un potenziale problema di performace.
2626

2727
Il metodo `result.includes(str)` internamente attraversa l'array `result` e confronta ogni elemento con `str` per trovare una corrispondenza.
2828

2929
Quindi se ci sono `100` elementi in `result` e nessuna corrispondenza con `str`, attraverseremo l'intero array `result` eseguendo essattamente `100` confronti. Se l'array `result` è grande, ad esempio `10000`, ci sarebbero `10000` di confronti.
3030

3131
Non è propriamente un problema, perché il motore JavaScript è molto rapido, quindi un array grande `10000` è questione di pochi microsecondi.
3232

33-
Ma dovremo eseguire questo test per ogni elemento di `arr`, nel ciclo `for`.
33+
Ma dovremo eseguire questo test per ogni elemento di `arr` nel ciclo `for`.
3434

3535
Quindi se `arr.length` è `10000` avremmo qualcosa come `10000*10000` = 100 milioni di confronti. Sono molti.
3636

1-js/05-data-types/05-array-methods/11-array-unique/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 4
66

77
Abbiamo un array `arr`.
88

9-
Create una funzione `unique(arr)` che dovrebbe ritornare un array con elementi unici.
9+
Create una funzione `unique(arr)` che ritorni un array con elementi unici.
1010

1111
Ad esempio:
1212

1-js/05-data-types/05-array-methods/12-reduce-object/task.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ importance: 4
22

33
---
44

5-
# Create keyed object from array
5+
# Create un oggetto da un array
66

7-
Let's say we received an array of users in the form `{id:..., name:..., age... }`.
87

9-
Create a function `groupById(arr)` that creates an object from it, with `id` as the key, and array items as values.
8+
Immaginiamo di ricevere un array di utenti nella forma `{id:..., name:..., age... }`.
109

11-
For example:
10+
Scrivi una funzione `groupById(arr)` che ricavi un oggetto da esso, con `id` come chiave e gli elementi dell'array come valori
11+
12+
Ad esempio:
1213

1314
```js
1415
let users = [
@@ -20,7 +21,7 @@ let users = [
2021
let usersById = groupById(users);
2122

2223
/*
23-
// after the call we should have:
24+
// dopo la chiamata dovremmo avere:
2425
2526
usersById = {
2627
john: {id: 'john', name: "John Smith", age: 20},
@@ -30,8 +31,8 @@ usersById = {
3031
*/
3132
```
3233

33-
Such function is really handy when working with server data.
34+
Una funzione simile è molto utile quando si lavora con dati provenienti da un server.
3435

35-
In this task we assume that `id` is unique. There may be no two array items with the same `id`.
36+
In questo esercizio sappiamo che `id` è unico. Non ci saranno due array con lo stesso `id`.
3637

37-
Please use array `.reduce` method in the solution.
38+
Per favore utilizza il metodo `.reduce` nella soluzione.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
function filterRange(arr, a, b) {
3-
// added brackets around the expression for better readability
3+
//aggiunte parentesi attorno all'espressione per una migliore leggibilità
44
return arr.filter(item => (a <= item && item <= b));
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
```js run demo
22
function filterRange(arr, a, b) {
3-
// added brackets around the expression for better readability
3+
//aggiunte parentesi attorno all'espressione per una migliore leggibilità
44
return arr.filter(item => (a <= item && item <= b));
55
}
66

77
let arr = [5, 3, 8, 1];
88

99
let filtered = filterRange(arr, 1, 4);
1010

11-
alert( filtered ); // 3,1 (matching values)
11+
alert( filtered ); // 3,1 (i valori filtrati)
1212

13-
alert( arr ); // 5,3,8,1 (not modified)
13+
alert( arr ); // 5,3,8,1 (non modificato)
1414
```

1-js/05-data-types/05-array-methods/2-filter-range/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 4
44

55
# Filtri
66

7-
Scrivete una funzione `filterRange(arr, a, b)` che prende un array `arr`, cerca un elemento tra `a` e `b` e ne ritorna un array.
7+
Scrivete una funzione `filterRange(arr, a, b)` che accetta come argomento un array `arr`, filtra gli elementi tra `a` e `b` e ne ritorna un array.
88

99
La funzione non dovrebbe modificare l'array. Dovrebbe invece ritornare il nuovo array.
1010

@@ -15,8 +15,8 @@ let arr = [5, 3, 8, 1];
1515

1616
let filtered = filterRange(arr, 1, 4);
1717

18-
alert( filtered ); // 3,1 (matching values)
18+
alert( filtered ); // 3,1 (i valori filtrati)
1919

20-
alert( arr ); // 5,3,8,1 (not modified)
20+
alert( arr ); // 5,3,8,1 (non modificato)
2121
```
2222

1-js/05-data-types/05-array-methods/3-filter-range-in-place/_js.view/solution.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function filterRangeInPlace(arr, a, b) {
44
for (let i = 0; i < arr.length; i++) {
55
let val = arr[i];
66

7-
// remove if outside of the interval
7+
// rimuove se fuori dal range
88
if (val < a || val > b) {
99
arr.splice(i, 1);
1010
i--;

0 commit comments

Comments
 (0)