Skip to content

Commit bab53d3

Browse files
authored
Merge pull request #138 from josemoracard/jose5-15-max-integer-from-array
exercises 15-max-integer-from-array to 20.3-Map-with-function-inside-a-variable
2 parents 9cdc105 + dc78a94 commit bab53d3

40 files changed

+245
-209
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# `15` El máximo número entero dentro del arreglo
22

3-
## 📝Instrucciones:
3+
## 📝 Instrucciones:
44

5-
1. Escribe un script que encuentre el número entero más grande en `myArray`.
5+
1. Escribe una función llamada `findMax` que encuentre el número entero más grande dentro de un array.
66

77
2. Imprime ese número en la consola con la función `console.log()`.
88

9-
### 💡 Pista:
9+
## 💡 Pistas:
1010

11-
- Define una variable auxiliar y establece el primer valor en 0,
11+
- Define una variable auxiliar. ¿Cuál debería ser su valor inicial?
1212

13-
- Luego compara las variables con todos los elementos del arreglo.
13+
- Luego compara la variable auxiliar con todos los elementos del arreglo.
1414

1515
- Reemplaza el valor cada vez que el nuevo elemento sea más grande que el almacenado en la variable auxiliar.
1616

17-
- Al final tendrá el mayor número almacenado en la variable.
17+
- Al final tendrás el mayor número almacenado en la variable.
18+
19+
## 💻 Resultado esperado:
1820

19-
### Resultado esperado:
2021
```js
21-
5435
22-
```
22+
console.log(findMax(myArray)); // --> 5435
23+
```
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
# `15` Max integer from the array
22

3+
## 📝 Instructions:
34

4-
## 📝Instructions:
5+
1. Write a function `findMax` that finds the largest integer in any array that is passed to it as a parameter.
56

6-
1. Write a function `findMax` that finds the greatest integer in any array that is passed to it as a parameter.
7+
2. Print that largest integer in the console with the `console.log()` function.
78

8-
2. Print that greatest integer in the console with the `console.log()` function.
9-
10-
11-
### 💡 Hint:
9+
## 💡 Hints:
1210

1311
- Define an auxiliary variable. What should its initial value be?
1412

1513
- Then compare the auxiliary variable with every number in the list.
1614

1715
- Replace the value of the auxiliary variable with that of every encountered number that is greater than the auxiliary.
1816

19-
- At the end you will have the biggest number stored in the variable.
20-
17+
- At the end, you will have the largest number stored in the variable.
2118

22-
### Expected result:
19+
## 💻 Expected result:
2320

2421
```js
25-
26-
console.log(findMax(myArray)); //prints 5435
27-
22+
console.log(findMax(myArray)); // --> 5435
2823
```
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
let myArray = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34];
1+
let myArray = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34];
2+
3+
// Your code here
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
let myArray = [43, 23, 6, 87, 43, 1, 4, 6, 3, 67, 8, 3445, 3, 7, 5435, 63, 346, 3, 456, 734, 6, 34];
1+
let myArray = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34];
22

3-
function findMax(myArray) {
3+
// Your code here
4+
function findMax(arr) {
45

5-
let maxNum = myArray[0];
6+
let maxNum = arr[0];
67

7-
for (let i = 1; i < myArray.length; i++) {
8-
if (myArray[i] > maxNum)
9-
maxNum = myArray[i];
8+
for (let i = 1; i < arr.length; i++) {
9+
if (arr[i] > maxNum)
10+
maxNum = arr[i];
1011
}
1112

1213
return maxNum;
1314
}
14-
console.log(findMax(myArray))
15+
16+
console.log(findMax(myArray))

exercises/15-Max-integer-from-array/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ it('You have to use the console.log function', function () {
3030
const app = require('./app.js');
3131
expect(console.log.mock.calls.length > 0).toBe(true);
3232
});
33-
it('The output in the console should match the one in the instructions!', function () {
33+
it('The output in the console should match the one in the instructions', function () {
3434
//You can also compare the entire console buffer (if there have been several console.log calls on the exercise)
3535
expect(_buffer.includes("5435\n")).toBe(true);
36-
});
36+
});

exercises/16-Foreach-min-val/README.es.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
# `16` Número entero menor:
1+
# `16` Minimum integer
22

3-
Es posible recorrer un arreglo usando la función `array.forEach`. Debes especificar qué hacer en cada iteración del bucle.
4-
```js
3+
Es posible recorrer un arreglo usando el método `array.forEach()`. Debes especificar qué hacer en cada iteración del bucle.
54

6-
myArray.forEach(function(item, index, arr){
5+
```js
6+
myArray.forEach(function(item, index, arr) {
77
console.log(item, index)
8-
//item es el valor específico del elemento.
9-
//index será el índice del elemento.
10-
//arr será el array al cual pertenece el elemento.
8+
// item es el valor de cada elemento.
9+
// index será el índice del elemento.
10+
// arr será el array al cual pertenece el elemento.
1111
});
12-
1312
```
13+
1414
## 📝 Instrucciones:
1515

16-
1. Utiliza la función `forEach` para obtener el valor mínimo del arreglo e imprimirlo en la consola.
16+
1. Utiliza el método `forEach()` para obtener el valor mínimo del arreglo e imprimirlo en la consola.
1717

18-
### 💡 Pista:
18+
## 💡 Pistas:
1919

20-
- Declarar una variable global auxiliar
20+
- Declara una variable global auxiliar.
2121

22-
- Establece un valor de un número entero muy grande.
22+
- Establece su valor a un número entero muy grande.
2323

24-
- Cada vez que realices un loop(bucle), compara su valor con el valor del número entero grande, si el valor del elemento es menor, actualiza el valor de la variable auxiliar al valor del elemento.
24+
- Cada vez que realices un bucle, compara su valor con el valor de la variable, si el valor del elemento es menor, actualiza el valor de la variable auxiliar al valor del elemento.
2525

26-
- Fuera del bucle, una vez finalizado el bucle, imprima el valor auxiliar.
26+
- Ya fuera del bucle, imprime el valor de la variable auxiliar.
2727

28-
### Resultado esperado:
28+
## 💻 Resultado esperado:
2929

3030
```js
3131
23
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
1+
# `16` Minimum integer
12

2-
# `16` Minimum integer:
3-
4-
It is possible to traverse an array using the `array.forEach` function. You have to specify what to do on each iteration of the loop.
3+
It is possible to traverse an array using the `array.forEach()` method. You have to specify what to do on each iteration of the loop.
54

65
```js
7-
8-
myArray.forEach(function(item, index){
6+
myArray.forEach(function(item, index, arr) {
97
console.log(item, index)
10-
//item will be the value of the specific item.
11-
//index will be the item index.
12-
//arr will be the array object to which the element belongs to.
8+
// item will be the value of each item.
9+
// index will be the item's index.
10+
// arr will be the array object to which the element belongs to.
1311
});
14-
1512
```
1613

17-
1814
## 📝 Instructions:
1915

20-
1. Please use the `forEach` function to get the minimum value of the array and print it in the console.
21-
22-
### 💡 Hint:
16+
1. Please use the `forEach()` method to get the minimum value of the array and print it in the console.
2317

24-
- Declare an auxiliar global variable
18+
## 💡 Hints:
2519

26-
- Set its value to a very big integer
20+
- Declare an auxiliary global variable.
2721

28-
- Every time you loop compare its value to the item value, if the item value is smaller update the auxiliar variable value to the item value.
22+
- Set its value to a very big integer.
2923

30-
- Outside of the loop, after the loop is finished, print the auxiliar value.
24+
- Every time you loop, compare its value to the item value, if the item value is smaller, update the auxiliary variable's value to the item value.
3125

26+
- Outside the loop, after the loop is finished, print the auxiliary value.
3227

33-
### Expected result:
28+
## 💻 Expected result:
3429

3530
```js
36-
23
37-
```
31+
23
32+
```

exercises/16-Foreach-min-val/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
let myArray = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343];
22

3-
//your code here
3+
// Your code here
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let myArray = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343];
2+
3+
// Your code here
4+
let minNum = Infinity;
5+
6+
myArray.forEach(function(item) {
7+
if (item < minNum) {
8+
minNum = item;
9+
}
10+
});
11+
12+
console.log(minNum);

exercises/16-Foreach-min-val/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ it('You have to use the console.log function', function () {
2525
const app = require('./app.js');
2626
expect(console.log.mock.calls.length > 0).toBe(true);
2727
});
28-
it('The output in the console should match the one in the instructions!', function () {
28+
it('The output in the console should match the one in the instructions', function () {
2929
//You can also compare the entire console buffer (if there have been several console.log calls on the exercise)
3030
expect(_buffer.includes("23\n")).toBe(true);
31-
});
31+
});

exercises/17-The-for-loop/README.es.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
# `17` Un For Loop para encontrar un promedio
1+
# `17` The For...of loop get average
22

33
Otra forma de recorrer un arreglo con el loop `for` es usando la declaración `of` de esta manera:
44

55
```js
6-
for (let item of myArray){
7-
console.log(item);
6+
for (let element of myArray) {
7+
console.log(element);
88
}
99
```
1010

11+
El bucle `for...of` te proporciona acceso directo a los elementos (como se muestra arriba), sin que tengas que utilizar el formato `array[index]` para acceder al valor de un elemento.
12+
13+
Esto hace que este tipo de bucle sea más sencillo de usar; sin embargo, no te proporciona acceso a los índices, por lo que si necesitas utilizar los índices de los elementos, no podrás hacerlo.
14+
15+
Puedes aprender más sobre este tipo de bucles aquí:
16+
[https://www.w3schools.com/js/js_loop_forof.asp](https://www.w3schools.com/js/js_loop_forof.asp)
17+
1118
## 📝 Instrucciones:
1219

1320
1. Calcula el valor promedio de todos los elementos del arreglo.
1421

1522
2. Imprímelo en la consola.
1623

17-
## 💡 Pista:
24+
## 💡 Pistas:
25+
26+
+ Recuerda utilizar variables auxiliares.
1827

19-
+ Para imprimir el promedio, debes sumar todos los valores y dividir el resultado por la longitud (length) total del arreglo.
28+
+ Para obtener el promedio, debes sumar todos los valores y dividir el resultado por la longitud total del arreglo.
2029

21-
## Resultado esperado:
30+
## 💻 Resultado esperado:
2231

2332
```js
2433
27278.8125

exercises/17-The-for-loop/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
# `17` The For Loop Find average
1+
# `17` The For...of loop get average
22

3-
Another way to loop an array with the `for` loop will be using the `of` statement like this:
3+
Another way to loop an array with the `for` loop is to use the `of` statement like this:
44

55
```js
6-
for (let element of myArray){
6+
for (let element of myArray) {
77
console.log(element);
88
}
99
```
1010

11-
The for-of loop gives you direct access to the elements (as seen above), without you having to use the format array[index] to access the value of an element.
11+
The `for...of` loop gives you direct access to the elements (as seen above), without you having to use the format `array[index]` to access the value of an element.
1212

13-
That makes this type of loop simpler to use, however it does not give you access to indexes, so if you will need to use the indexes of the elements, then you will not be able to use it.
13+
That makes this type of loop simpler to use; however it does not give you access to indexes, so if you need to use the indexes of the elements, you wont be able to.
1414

1515
You can learn more about these loops here:
1616
[https://www.w3schools.com/js/js_loop_forof.asp](https://www.w3schools.com/js/js_loop_forof.asp)
1717

1818
## 📝 Instructions:
1919

20-
1. Calculate the average value of all the items in the array
20+
1. Calculate the average value of all the items in the array.
2121

2222
2. Print it on the console.
2323

24-
### 💡 Hint:
24+
## 💡 Hints:
2525

26-
+ To print the average, you have to add all the values and divide the result by the total length of the list.
26+
+ Remember to use auxiliary variables.
2727

28+
+ To get the average, you have to add all the values and divide the result by the total length of the list.
2829

29-
### Expected result:
30+
## 💻 Expected result:
3031

3132
```js
3233
27278.8125

exercises/17-The-for-loop/app.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
let myArray = [2323, 4344, 2325, 324413, 21234, 24531, 2123, 42234, 544, 456, 345, 42, 5445, 23, 5656, 423];
22

3-
let avg = 0;
4-
for (let i of myArray) {
5-
avg += myArray[i]
6-
}
7-
let avgTest = avg / myArray.length
8-
9-
console.log(avgTest)
3+
// Your code here
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
let myArray = [2323, 4344, 2325, 324413, 21234, 24531, 2123, 42234, 544, 456, 345, 42, 5445, 23, 5656, 423];
22

3-
let avg = 0;
3+
// Your code here
4+
let totalSum = 0;
45
for (let i of myArray) {
5-
avg += i
6+
totalSum += i
67
}
7-
let avgTest = avg / myArray.length
88

9-
console.log(avgTest)
9+
let avg = totalSum / myArray.length
10+
11+
console.log(avg)

exercises/17-The-for-loop/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ it('You have to use the console.log function', function () {
2929
// //You can also compare the entire console buffer (if there have been several console.log calls on the exercise)
3030
// expect(_buffer.includes("27278.8125\n")).toBe(true);
3131
// });
32-
it('The output in the console should match the one in the instructions!', function () {
32+
it('The output in the console should match the one in the instructions', function () {
3333
const _app = rewire('./app.js');
3434

3535
let _myArray = [2323,4344,2325,324413,21234,24531,2123,42234,544,456,345,42,5445,23,5656,423];

exercises/18-Nested-arrays/README.es.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# `18` Arrays/arreglos anidados
1+
# `18` Nested Arrays
22

3-
Es posible encontrar un arreglo compuesto por otros arreglos (se llama arreglo o arreglo de dos dimensiones).
3+
Es posible encontrar un arreglo compuesto por otros arreglos (se llama matriz o arreglo de dos dimensiones).
44

5-
En este ejemplo, tenemos una array o arreglo de coordenadas a las que puedes acceder haciendo lo siguiente:
5+
En este ejemplo, tenemos un array de coordenadas a las que puedes acceder haciendo lo siguiente:
66

77
```js
8-
//la primera coordenada latitud
8+
// La primera coordenada es latitud
99
let latitude = coordinatesArray[0][0];
10-
//la primera coordenada longitud
10+
// La segunda coordenada es longitud
1111
let longitude = coordinatesArray[0][1];
1212
```
1313

14-
## 📝 Instruciones:
14+
## 📝 Instrucciones:
1515

1616
1. Recorre el arreglo (con un bucle) imprimiendo solo las longitudes.
1717

18-
### Resultado esperado:
18+
## 💻 Resultado esperado:
1919

2020
```js
2121
-112.633853

0 commit comments

Comments
 (0)