Skip to content

Commit 2a31489

Browse files
Merge pull request 4GeeksAcademy#194 from josemoracard/jose1-110-getAllButLastElementOfProperty
ejercicios cambios varios
2 parents 2164d02 + efbb1f4 commit 2a31489

File tree

47 files changed

+168
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+168
-133
lines changed

exercises/065-or/README.es.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# `065` or
22

3+
En este ejercicio vamos a replicar el comportamiento del operador lógico OR `||` sin usar el propio operador. ¿Recuerdas cómo funciona?
4+
35
## 📝 Instrucciones:
46

5-
1. Escribe una función llamada `or`. Dadas 2 expresiones booleanas, `or` retorna true o false, correspondiente al operador `||`.
7+
1. Escribe una función llamada `or`. Dadas 2 expresiones booleanas, `or` retorna true o false, siguiendo las reglas del operador `||`.
68

79
## 📎 Ejemplo:
810

exercises/065-or/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# `065` or
22

3+
In this exercise, we are going to replicate the behavior of the logical operator OR `||` without actually using the operator itself. Do you remember how it works?
4+
35
## 📝 Instructions:
46

5-
1. Write a function called `or`. Given 2 boolean expressions, `or` returns true or false, corresponding to the `||` operator.
7+
1. Write a function called `or`. Given 2 boolean expressions, `or` returns true or false, following the rules of the `||` operator.
68

79
## 📎 Example:
810

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
function getLengthOfLongestElement(arr) {
2-
// Your code here
3-
if (arr.length < 1) return 0
4-
else {
5-
let aux = 0
6-
arr.map(item=> item.length > aux ? aux = item.length : null)
7-
return aux;
2+
// your code here
3+
let longestLength = 0;
4+
for (let i = 0; i < arr.length; i++) {
5+
if (arr[i].length > longestLength) {
6+
longestLength = arr[i].length;
87
}
8+
}
9+
10+
return longestLength;
911
}
1012

1113
let output = getLengthOfLongestElement(['one', 'two', 'three']);
12-
console.log(output); // --> 5
14+
console.log(output); // --> 5

exercises/111-getElementOfArrayProperty/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 📝 Instrucciones:
44

5-
1. Escribe una función llamada `getElementOfArrayProperty`. Dados un objeto, una key y un index númerico, `getElementOfArrayProperty` retorna el valor de un elemento en el index proporcionado del array ubicado dentro del objeto en la key dada.
5+
1. Escribe una función llamada `getElementOfArrayProperty`. Dados un objeto, una key y un index numérico, `getElementOfArrayProperty` retorna el valor de un elemento en el index proporcionado del array ubicado dentro del objeto en la key dada.
66

77
## 📎 Ejemplo:
88

exercises/120-getLargestElement/solution.hide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function getLargestElement(arr) {
22
// your code here
33
if (arr.length < 1) return 0;
44

5-
let aux = 0;
5+
let aux = arr[0];
66
for (let e of arr) {
77
if (aux < e) aux = e;
88
}

exercises/120-getLargestElement/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ test('Function must return the largest number within the array. Testing with dif
2121
expect(getLargestElement([15, 22, 18, 23])).toBe(23);
2222
});
2323

24+
test('Function must return the largest number within the array. Testing with different values', () => {
25+
expect(getLargestElement([-5, -2, -8, -3])).toBe(-2);
26+
});
27+
2428
test('If array is empty, it should return 0', () => {
2529
let output = getLargestElement([]);
2630
expect(output).toBe(0);

exercises/121-computeSumOfAllElements/solution.hide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function computeSumOfAllElements(arr) {
77
return aux;
88
}
99

10-
var output = computeSumOfAllElements([1, 2, 3]);
10+
let output = computeSumOfAllElements([1, 2, 3]);
1111
console.log(output); // --> 6

exercises/124-joinArraysOfArrays/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 📝 Instrucciones:
44

5-
1. Escribe una función llamada `joinArrayOfArrays`. Dado una matriz (array de arrays), `joinArrayOfArrays` retorna un array único que contenga los elementos de los arrays anidados.
5+
1. Escribe una función llamada `joinArrayOfArrays`. Dada una matriz (array de arrays), `joinArrayOfArrays` retorna un array único que contenga los elementos de los arrays anidados.
66

77
## 📎 Ejemplo:
88

exercises/133-convertScoreToGrade/README.es.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ console.log(output); // --> 'A'
1313

1414
## 💡 Pistas:
1515

16-
+ (100 - 90) --> 'A'
17-
18-
+ (89 - 80) --> 'B'
19-
20-
+ (79 - 70) --> 'C'
21-
22-
+ (69 - 60) --> 'D'
23-
24-
+ (59 - 0) --> 'F'
16+
| Puntaje | Grado |
17+
|:---------:|:-------:|
18+
| 100 - 90 | 'A' |
19+
| 89 - 80 | 'B' |
20+
| 79 - 70 | 'C' |
21+
| 69 - 60 | 'D' |
22+
| 59 - 0 | 'F' |
2523

2624
+ Si la puntuación dada es mayor que 100 o menor que 0, `convertScoreToGrade` debería retornar `INVALID SCORE`.

exercises/133-convertScoreToGrade/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ console.log(output); // --> 'A'
1313

1414
## 💡 Hints:
1515

16-
+ (100 - 90) --> 'A'
17-
18-
+ (89 - 80) --> 'B'
19-
20-
+ (79 - 70) --> 'C'
21-
22-
+ (69 - 60) --> 'D'
23-
24-
+ (59 - 0) --> 'F'
16+
| Score | Grade |
17+
|:---------:|:-------:|
18+
| 100 - 90 | 'A' |
19+
| 89 - 80 | 'B' |
20+
| 79 - 70 | 'C' |
21+
| 69 - 60 | 'D' |
22+
| 59 - 0 | 'F' |
2523

2624
+ If the given score is greater than 100 or less than 0, `convertScoreToGrade` should return `INVALID SCORE`.

exercises/134-convertScoreToGradeWithPlus/README.es.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ console.log(output); // --> 'A-'
1313

1414
## 💡 Pistas:
1515

16-
+ (100 - 90) --> 'A'
17-
18-
+ (89 - 80) --> 'B'
19-
20-
+ (79 - 70) --> 'C'
21-
22-
+ (69 - 60) --> 'D'
23-
24-
+ (59 - 0) --> 'F'
16+
| Puntaje | Grado |
17+
|:---------:|:-------:|
18+
| 100 - 90 | 'A' |
19+
| 89 - 80 | 'B' |
20+
| 79 - 70 | 'C' |
21+
| 69 - 60 | 'D' |
22+
| 59 - 0 | 'F' |
2523

2624
+ Si el puntaje dado es mayor que 100 o menor que 0, debería retornar `INVALID SCORE`.
2725

exercises/134-convertScoreToGradeWithPlus/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ console.log(output); // --> 'A-'
1313

1414
## 💡 Hints:
1515

16-
+ (100 - 90) --> 'A'
17-
18-
+ (89 - 80) --> 'B'
19-
20-
+ (79 - 70) --> 'C'
21-
22-
+ (69 - 60) --> 'D'
23-
24-
+ (59 - 0) --> 'F'
16+
| Score | Grade |
17+
|:--------: |:-----: |
18+
| 100 - 90 | 'A' |
19+
| 89 - 80 | 'B' |
20+
| 79 - 70 | 'C' |
21+
| 69 - 60 | 'D' |
22+
| 59 - 0 | 'F' |
2523

2624
+ If the given score is greater than 100 or less than 0, it should return `INVALID SCORE`.
2725

exercises/135-computeFactorialOfN/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ function computeFactorialOfN(n) {
33

44
}
55

6-
let output = computeFactorialOfN(3);
7-
console.log(output); // --> 6
6+
let output = computeFactorialOfN(4);
7+
console.log(output); // --> 24

exercises/135-computeFactorialOfN/solution.hide.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ function computeFactorialOfN(n) {
55
return aux;
66
}
77

8-
let output = computeFactorialOfN(3);
9-
console.log(output); // --> 6
10-
118
let output = computeFactorialOfN(4);
129
console.log(output); // --> 24

exercises/139-computeCompoundInterest/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ console.log(output); // --> 438.83682213410543
1313

1414
## 💡 Pista:
1515

16-
- Aquí puedes ver la fórmula utilizada para calcular el interés compuesto total generado: [Calculation_of_compound_interest](https://en.wikipedia.org/wiki/Compound_interest#Calculation_of_compound_interest)
16+
- Aquí puedes ver la fórmula utilizada para calcular el interés compuesto total generado: [Calculation_of_compound_interest](https://en.wikipedia.org/wiki/Compound_interest#Calculation)

exercises/139-computeCompoundInterest/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ let output = computeCompoundInterest(1500, .043, 4, 6);
1111
console.log(output); // --> 438.83682213410543
1212
```
1313

14-
## 💡 Hints:
14+
## 💡 Hint:
1515

16-
- Check the formula used to calculate the total compound insterest generated: [Calculation_of_compound_interest](https://en.wikipedia.org/wiki/Compound_interest#Calculation_of_compound_interest)
16+
- Check the formula used to calculate the total compound insterest generated: [Calculation_of_compound_interest](https://en.wikipedia.org/wiki/Compound_interest#Calculation)

exercises/140-modulo/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ console.log(output); // --> 1
1313

1414
## 💡 Pistas:
1515

16-
+ La función debe comportarse como se describe en la [documentación canónica (MDN) para el operador resto de JavaScript](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Operators/Remainder)
16+
+ La función debe comportarse como se describe en la [documentación canónica (MDN) para el operador resto de JavaScript](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Operators/Remainder).
1717

1818
+ NO uses el operador de módulo incorporado (también conocido como "resto") (`%`) en la implementación.
1919

exercises/140-modulo/solution.hide.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function modulo(num1, num2) {
22
// your code here
3+
if (num2 === 0 || isNaN(num1) || isNaN(num2)) {
4+
return NaN;
5+
}
6+
37
let i = 0;
48
if(num1 > 0) {
59
while (i < num1) {

exercises/141-multiply/solution.hide.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
function multiply(num1, num2) {
22
// your code here
3-
let aux = 0;
4-
if (num1 < 0) {
5-
for (let times = 0; times < num2; times++) aux += num1;
6-
} else {
7-
for (let times = 0; times < num1; times++) aux += num2;
3+
let result = 0;
4+
let isNegative = false;
5+
6+
// Check if the result will be negative
7+
if ((num1 < 0 && num2 > 0) || (num1 > 0 && num2 < 0)) {
8+
isNegative = true;
9+
}
10+
11+
// Convert both numbers to positive
12+
num1 = Math.abs(num1);
13+
num2 = Math.abs(num2);
14+
15+
// Add num1 to result num2 times
16+
for (let i = 0; i < num2; i++) {
17+
result += num1;
818
}
9-
return aux;
19+
20+
// If the result should be negative, negate it
21+
if (isNegative) {
22+
result = -result;
23+
}
24+
25+
return result;
1026
}
1127

1228
let output = multiply(2, -7);

exercises/141-multiply/test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ test('Function multiply must return a number', () => {
1313
expect(typeof multiply(1, 2)).toBe('number');
1414
});
1515

16-
test('Given 2 whole numbers, multiply and return the total', () => {
16+
test('Given 2 integer numbers, multiply and return the total', () => {
1717
expect(multiply(4, 7)).toBe(28);
1818
});
1919

20-
test('Given 2 whole numbers, multiply and return the total. Testing with negative value', () => {
20+
test('Given 2 integer numbers, multiply and return the total. Testing with different values', () => {
2121
expect(multiply(5, -5)).toBe(-25);
2222
});
2323

24+
test('Given 2 integer numbers, multiply and return the total. Testing with different values', () => {
25+
expect(multiply(-5, -3)).toBe(15);
26+
});
27+
28+
test('Given 2 integer numbers, multiply and return the total. Testing with different values', () => {
29+
expect(multiply(0, -5)).toBe(0);
30+
});
31+
2432
test('Must not use the * operator', () => {
2533
let multiplyOperator = '*';
2634
expect(multiplyOperator).not.toBe(multiply);

exercises/142-isOddWithoutModulo/solution.hide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function isOddWithoutModulo(num) {
22
// your code here
33
let aux = true;
4-
if(num >= 0){
4+
if (num >= 0) {
55
for (let x = 0; x <= num + 1; x += 2) {
66
if (x === num) aux = false;
77
}

exercises/143-isEvenWithoutModulo/solution.hide.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ function isEvenWithoutModulo(num) {
1313
return aux;
1414
}
1515

16-
let output = isEvenWithoutModulo(18);
17-
console.log(output); // --> false
16+
let output = isEvenWithoutModulo(8);
17+
console.log(output); // --> true

exercises/143-isEvenWithoutModulo/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('Function isEvenWithoutModulo must exist', () => {
55
expect(isEvenWithoutModulo).not.toBe(undefined);
66
});
77

8-
test('Function isEvenWithoutModulo must exist', () => {
8+
test('Function isEvenWithoutModulo must return something', () => {
99
expect(isEvenWithoutModulo(1)).not.toBe(undefined);
1010
});
1111

exercises/146.1-ArrayToObject/README.es.md

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

33
## 📝 Instrucciones:
44

5-
1. Escribe una función `transformFirstAndLast` que tome un array y devuelva un objeto cuyo *primer elemento sea la key del objeto*, y cuyo *último elemento sea el valor de esa key*.
5+
1. Escribe una función `transformFirstAndLast` que tome un array y devuelva un objeto cuyo **primer elemento sea la key del objeto**, y cuyo **último elemento sea el valor de esa key**.
66

77
## 📎 Ejemplo 1:
88

99
```js
1010
let output = transformFirstAndLast(['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce'])
11-
console.log(output); // { Queen: "Beyonce" }
11+
console.log(output); // --> { Queen: "Beyonce" }
1212
```
1313

1414
## 📎 Ejemplo 2:
1515

1616
```js
1717
let output = transformFirstAndLast(['Kevin', 'Bacon', 'Love', 'Hart', 'Costner', 'Spacey'])
18-
console.log(output); // { Kevin: "Spacey" }
18+
console.log(output); // --> { Kevin: "Spacey" }
1919
```
2020

2121
## 💡 Pistas:
@@ -24,4 +24,4 @@ console.log(output); // { Kevin: "Spacey" }
2424

2525
+ Asume que todos los elementos en el array de entrada serán del tipo `string`.
2626

27-
+ Ten en cuenta que el array de entrada puede teneruna cantidad variable de elementos por lo que tu código debe ser flexible.
27+
+ Ten en cuenta que el array de entrada puede tener una cantidad variable de elementos por lo que tu código debe ser flexible.

exercises/146.1-ArrayToObject/README.md

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

33
## 📝 Instructions:
44

5-
1. Write a function called `transformFirstAndLast` that takes in an array, and returns an object with *the first element of the array as the object's key*, and *the last element of the array as that key's value*.
5+
1. Write a function called `transformFirstAndLast` that takes in an array, and returns an object with **the first element of the array as the object's key**, and **the last element of the array as that key's value**.
66

77
## 📎 Example 1:
88

99
```js
1010
let output = transformFirstAndLast(['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce'])
11-
console.log(output); // { Queen: "Beyonce" }
11+
console.log(output); // --> { Queen: "Beyonce" }
1212
```
1313

1414
## 📎 Example 2:
1515

1616
```js
1717
let output = transformFirstAndLast(['Kevin', 'Bacon', 'Love', 'Hart', 'Costner', 'Spacey'])
18-
console.log(output); // { Kevin: "Spacey" }
18+
console.log(output); // --> { Kevin: "Spacey" }
1919
```
2020

2121
## 💡 Hints:

exercises/146.2-ArrayToObject/README.es.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# `146.2` ArraytoObject
1+
# `146.2` ArrayToObject
22

33
## 📝 Instrucciones:
44

5-
1. Escribe una función `fromListToObject` que tome una matriz (array de arrays), y retorne *un objeto con cada par de elementos de la matriz como un par clave-valor (key-value)*.
5+
1. Escribe una función `fromListToObject` que tome una matriz (array de arrays), y retorne **un objeto con cada par de elementos de la matriz como un par clave-valor (key-value)**.
66

77
## 📎 Ejemplo:
88

exercises/146.2-ArrayToObject/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# `146.2` ArraytoObject
1+
# `146.2` ArrayToObject
22

33
## 📝 Instructions:
44

5-
1. Write a function `fromListToObject` which takes in a matrix (an array of arrays), and returns an object with *each pair of elements in the array as a key-value pair*.
5+
1. Write a function `fromListToObject` which takes in a matrix (an array of arrays), and returns an object with **each pair of elements in the array as a key-value pair**.
66

77
## 📎 Example:
88

0 commit comments

Comments
 (0)