Skip to content

Commit e21ab8a

Browse files
authored
Merge pull request #1 from rztprog/master
Update 1-JS/05/05(Array-Methods) & 1-JS/05/08(Keys-Values-Entries)
2 parents 15a3ed2 + 2f3e9dc commit e21ab8a

File tree

21 files changed

+366
-367
lines changed

21 files changed

+366
-367
lines changed
Lines changed: 5 additions & 5 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']
4-
.map(
5-
// capitalizes first letters of all array items except the first one
6-
// converts ['my', 'long', 'word'] into ['my', 'Long', 'Word']
3+
.split('-') // divise 'my-long-word' en tableau ['my', 'long', 'word']
4+
.map(
5+
// capitalise les premières lettres de tous les éléments du tableau sauf le premier
6+
// convertit ['my', 'long', 'word'] en ['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(''); // rejoint ['my', 'Long', 'Word'] en -> myLongWord
1010
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 5
22

33
---
44

5-
# Translate border-left-width to borderLeftWidth
5+
# Traduit border-left-width en borderLeftWidth
66

7-
Write the function `camelize(str)` that changes dash-separated words like "my-short-string" into camel-cased "myShortString".
7+
Ecrivez la fonction `camelize(str)` qui change les mots séparés par des tirets comme "my-short-string" en camel-cased "myShortString".
88

9-
That is: removes all dashes, each word after dash becomes uppercased.
9+
Donc: supprime tous les tirets et met en majuscule la première lettre de chaque mot à partir du deuxième mot.
1010

11-
Examples:
11+
Exemples:
1212

1313
```js
1414
camelize("background-color") == 'backgroundColor';
1515
camelize("list-style-image") == 'listStyleImage';
1616
camelize("-webkit-transition") == 'WebkitTransition';
1717
```
1818

19-
P.S. Hint: use `split` to split the string into an array, transform it and `join` back.
19+
P.S. Astuce: utilisez `split` pour scinder la chaîne dans un tableau, transformer la et ensuite `join`.

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

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

33
---
44

5-
# Get average age
5+
# Obtenir l'âge moyen
66

7-
Write the function `getAverageAge(users)` that gets an array of objects with property `age` and gets the average.
7+
Ecrivez la fonction `getAverageAge(users)` qui obtient un tableau d'objets avec la propriété `age` et qui ensuite obtient la moyenne.
88

9-
The formula for the average is `(age1 + age2 + ... + ageN) / N`.
9+
La formule pour la moyenne est `(age1 + age2 + ... + ageN) / N`.
1010

11-
For instance:
11+
Par exemple:
1212

1313
```js no-beautify
1414
let john = { name: "John", age: 25 };
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Let's walk the array items:
2-
- For each item we'll check if the resulting array already has that item.
3-
- If it is so, then ignore, otherwise add to results.
1+
Parcourons les éléments du tableau:
2+
- Pour chaque élément, nous vérifierons si le tableau résultant contient déjà cet élément.
3+
- S'il en est ainsi, alors ignorez-le, sinon ajoutez aux résultats.
44

5-
```js run demo
5+
```js run
66
function unique(arr) {
77
let result = [];
88

@@ -22,18 +22,18 @@ let strings = ["Hare", "Krishna", "Hare", "Krishna",
2222
alert( unique(strings) ); // Hare, Krishna, :-O
2323
```
2424

25-
The code works, but there's a potential performance problem in it.
25+
Le code fonctionne, mais il comporte un problème de performances potentiel.
2626

27-
The method `result.includes(str)` internally walks the array `result` and compares each element against `str` to find the match.
27+
La méthode `result.includes(str)` parcourt en interne le tableau `result` et compare chaque élément à `str` pour trouver la correspondance.
2828

29-
So if there are `100` elements in `result` and no one matches `str`, then it will walk the whole `result` and do exactly `100` comparisons. And if `result` is large, like `10000`, then there would be `10000` comparisons.
29+
Donc, s'il y a `100` éléments dans` result` et que personne ne correspond à `str`, alors il parcourra tout le `result` et fera exactement les `100` comparaisons. Et si `result` est grand, exemple `10000`, alors il y aura des `10000` comparaisons .
3030

31-
That's not a problem by itself, because JavaScript engines are very fast, so walk `10000` array is a matter of microseconds.
31+
Ce n'est pas un problème en soi, parce que les moteurs JavaScript sont très rapides, alors parcourir un tableau de `10000` éléments est une question de microsecondes.
3232

33-
But we do such test for each element of `arr`, in the `for` loop.
33+
Mais nous faisons ce test pour chaque élément de `arr`, dans la boucle` for`.
3434

35-
So if `arr.length` is `10000` we'll have something like `10000*10000` = 100 millions of comparisons. That's a lot.
35+
Donc, si `arr.length` vaut `10000`, nous aurons quelque chose comme `10000*10000` = 100 millions de comparaisons. C'est beaucoup.
3636

37-
So the solution is only good for small arrays.
37+
La solution n’est donc valable que pour les petits tableaux.
3838

39-
Further in the chapter <info:map-set-weakmap-weakset> we'll see how to optimize it.
39+
Plus loin dans le chapitre <info:map-set-weakmap-weakset>, nous verrons comment l'optimiser.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 4
22

33
---
44

5-
# Filter unique array members
5+
# Filtrer les membres uniques du tableau
66

7-
Let `arr` be an array.
7+
`arr` est un tableau.
88

9-
Create a function `unique(arr)` that should return an array with unique items of `arr`.
9+
Créez une fonction `unique(arr)` qui devrait renvoyer un tableau avec des éléments uniques de `arr`.
1010

11-
For instance:
11+
Par exemple:
1212

1313
```js
1414
function unique(arr) {
15-
/* your code */
15+
/* votre code */
1616
}
1717

1818
let strings = ["Hare", "Krishna", "Hare", "Krishna",
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
```js run demo
2-
function filterRange(arr, a, b) {
3-
// added brackets around the expression for better readability
4-
return arr.filter(item => (a <= item && item <= b));
5-
}
6-
7-
let arr = [5, 3, 8, 1];
8-
9-
let filtered = filterRange(arr, 1, 4);
10-
11-
alert( filtered ); // 3,1 (matching values)
12-
13-
alert( arr ); // 5,3,8,1 (not modified)
14-
```
1+
```js run demo
2+
function filterRange(arr, a, b) {
3+
// ajout de crochets autour de l'expression pour une meilleure lisibilité
4+
return arr.filter(item => (a <= item && item <= b));
5+
}
6+
7+
let arr = [5, 3, 8, 1];
8+
9+
let filtered = filterRange(arr, 1, 4);
10+
11+
alert( filtered ); // 3,1 (valeur correspondate)
12+
13+
alert( arr ); // 5,3,8,1 (non modifié)
14+
```

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

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

55
# Filter range
66

7-
Write a function `filterRange(arr, a, b)` that gets an array `arr`, looks for elements between `a` and `b` in it and returns an array of them.
7+
Ecrivez une fonction `filterRange(arr, a, b)` qui obtient un tableau `arr`, recherche les éléments compris entre `a` et `b` et retourne un tableau.
88

9-
The function should not modify the array. It should return the new array.
9+
La fonction ne doit pas modifier le tableau. Elle doit juste retourner le nouveau tableau.
1010

11-
For instance:
11+
Par exemple:
1212

1313
```js
1414
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 (valeurs correspondantes)
1919

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ function filterRangeInPlace(arr, a, b) {
33

44
for (let i = 0; i < arr.length; i++) {
55
let val = arr[i];
6-
7-
// remove if outside of the interval
6+
7+
// enleve si en dehors de l'intervalle
88
if (val < a || val > b) {
99
arr.splice(i, 1);
1010
i--;
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
```js run demo
2-
function filterRangeInPlace(arr, a, b) {
3-
4-
for (let i = 0; i < arr.length; i++) {
5-
let val = arr[i];
6-
7-
// remove if outside of the interval
8-
if (val < a || val > b) {
9-
arr.splice(i, 1);
10-
i--;
11-
}
12-
}
13-
14-
}
15-
16-
let arr = [5, 3, 8, 1];
17-
18-
filterRangeInPlace(arr, 1, 4); // removed the numbers except from 1 to 4
19-
20-
alert( arr ); // [3, 1]
21-
```
1+
```js run demo
2+
function filterRangeInPlace(arr, a, b) {
3+
4+
for (let i = 0; i < arr.length; i++) {
5+
let val = arr[i];
6+
7+
// enleve si en dehors de l'intervalle
8+
if (val < a || val > b) {
9+
arr.splice(i, 1);
10+
i--;
11+
}
12+
}
13+
14+
}
15+
16+
let arr = [5, 3, 8, 1];
17+
18+
filterRangeInPlace(arr, 1, 4); // supprime les nombres sauf de 1 à 4
19+
20+
alert( arr ); // [3, 1]
21+
```

1-js/05-data-types/05-array-methods/3-filter-range-in-place/task.md

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

55
# Filter range "in place"
66

7-
Write a function `filterRangeInPlace(arr, a, b)` that gets an array `arr` and removes from it all values except those that are between `a` and `b`. The test is: `a ≤ arr[i] ≤ b`.
7+
Ecrivez une fonction `filterRangeInPlace(arr, a, b)` qui obtient un tableau `arr` et en supprime toutes les valeurs, sauf celles comprises entre `a` et `b`. Le test est: `a ≤ arr[i] ≤ b`.
88

9-
The function should only modify the array. It should not return anything.
9+
La fonction doit juste modifier que le tableau. Elle ne doit rien retourner.
1010

11-
For instance:
11+
Par exemple:
1212
```js
1313
let arr = [5, 3, 8, 1];
1414

15-
filterRangeInPlace(arr, 1, 4); // removed the numbers except from 1 to 4
15+
filterRangeInPlace(arr, 1, 4); // supprime les nombres qui ne sont pas entre 1 et 4
1616

1717
alert( arr ); // [3, 1]
1818
```

1-js/05-data-types/05-array-methods/4-sort-back/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ importance: 4
22

33
---
44

5-
# Sort in the reverse order
5+
# Trier dans l'ordre inverse
66

77
```js
88
let arr = [5, 2, 1, -10, 8];
99

10-
// ... your code to sort it in the reverse order
10+
// ... votre code pour le trier dans l'ordre inverse
1111

1212
alert( arr ); // 8, 5, 2, 1, -10
1313
```

1-js/05-data-types/05-array-methods/5-copy-sort-array/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 5
22

33
---
44

5-
# Copy and sort array
5+
# Copier et trier le tableau
66

7-
We have an array of strings `arr`. We'd like to have a sorted copy of it, but keep `arr` unmodified.
7+
Nous avons un tableau de chaînes `arr`. Nous aimerions en avoir une copie triée, mais sans modifier `arr`.
88

9-
Create a function `copySorted(arr)` that returns such a copy.
9+
Créez une fonction `copySorted(arr)` qui renvoie une copie triée.
1010

1111
```js
1212
let arr = ["HTML", "JavaScript", "CSS"];
1313

1414
let sorted = copySorted(arr);
1515

1616
alert( sorted ); // CSS, HTML, JavaScript
17-
alert( arr ); // HTML, JavaScript, CSS (no changes)
17+
alert( arr ); // HTML, JavaScript, CSS (aucune modification)
1818
```

1-js/05-data-types/05-array-methods/6-array-get-names/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ importance: 5
22

33
---
44

5-
# Map to names
5+
# Map en noms
66

7-
You have an array of `user` objects, each one has `user.name`. Write the code that converts it into an array of names.
7+
Vous avez un tableau d'objets `user`, chacun ayant` user.name`. Écrivez le code qui le convertit en un tableau de noms.
88

9-
For instance:
9+
Par exemple:
1010

1111
```js no-beautify
1212
let john = { name: "John", age: 25 };
1313
let pete = { name: "Pete", age: 30 };
1414
let mary = { name: "Mary", age: 28 };
1515

16-
let users = [ john, pete, mary ];
16+
let users = [ john, petemary ];
1717

18-
let names = /* ... your code */
18+
let names = /* ... votre code */
1919

2020
alert( names ); // John, Pete, Mary
2121
```

1-js/05-data-types/05-array-methods/7-map-objects/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Map to objects
5+
# Map en objets
66

7-
You have an array of `user` objects, each one has `name`, `surname` and `id`.
7+
Vous avez un tableau d'objets `user`, chacun ayant` name`, `surname` et` id`.
88

9-
Write the code to create another array from it, of objects with `id` and `fullName`, where `fullName` is generated from `name` and `surname`.
9+
Ecrivez le code pour créer un autre tableau à partir de celui-ci, avec les objets `id` et `fullName`, `fullName` est généré à partir de `name` et `surname`.
1010

11-
For instance:
11+
Par exemple:
1212

1313
```js no-beautify
1414
let john = { name: "John", surname: "Smith", id: 1 };
@@ -18,7 +18,7 @@ let mary = { name: "Mary", surname: "Key", id: 3 };
1818
let users = [ john, pete, mary ];
1919

2020
*!*
21-
let usersMapped = /* ... your code ... */
21+
let usersMapped = /* ... votre code ... */
2222
*/!*
2323

2424
/*
@@ -33,4 +33,4 @@ alert( usersMapped[0].id ) // 1
3333
alert( usersMapped[0].fullName ) // John Smith
3434
```
3535

36-
So, actually you need to map one array of objects to another. Try using `=>` here. There's a small catch.
36+
Donc, en réalité, vous devez mapper un tableau d'objets sur un autre. Essayez d'utiliser `=>` ici. Il y a une petite prise.

1-js/05-data-types/05-array-methods/8-sort-objects/solution.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
```js run no-beautify
2-
function sortByAge(arr) {
3-
arr.sort((a, b) => a.age > b.age ? 1 : -1);
2+
function sortByName(arr) {
3+
arr.sort((a, b) => a.name > b.name);
44
}
55

66
let john = { name: "John", age: 25 };
77
let pete = { name: "Pete", age: 30 };
88
let mary = { name: "Mary", age: 28 };
99

10-
let arr = [ pete, john, mary ];
10+
let arr = [ john, pete, mary ];
1111

12-
sortByAge(arr);
12+
sortByName(arr);
1313

14-
// now sorted is: [john, mary, pete]
14+
// maitenant trié il est: [john, mary, pete]
1515
alert(arr[0].name); // John
1616
alert(arr[1].name); // Mary
1717
alert(arr[2].name); // Pete

1-js/05-data-types/05-array-methods/8-sort-objects/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ importance: 5
22

33
---
44

5-
# Sort users by age
5+
# Trier les objets
66

7-
Write the function `sortByAge(users)` that gets an array of objects with the `age` property and sorts them by `age`.
7+
Ecrivez la fonction `sortByName(users)` qui obtient un tableau d'objets avec la propriété `name` et le trie.
88

9-
For instance:
9+
Par exemple:
1010

1111
```js no-beautify
1212
let john = { name: "John", age: 25 };
1313
let pete = { name: "Pete", age: 30 };
1414
let mary = { name: "Mary", age: 28 };
1515

16-
let arr = [ pete, john, mary ];
16+
let arr = [ john, pete, mary ];
1717

18-
sortByAge(arr);
18+
sortByName(arr);
1919

20-
// now: [john, mary, pete]
20+
// maintenant: [john, mary, pete]
2121
alert(arr[0].name); // John
2222
alert(arr[1].name); // Mary
2323
alert(arr[2].name); // Pete

0 commit comments

Comments
 (0)