Skip to content

Commit 5716f59

Browse files
Merge pull request #193 from josemoracard/jose10-cambios.varios2
Jose10 cambios.varios2
2 parents 3035781 + 250a0d5 commit 5716f59

File tree

24 files changed

+86
-67
lines changed

24 files changed

+86
-67
lines changed

exercises/083-getAllElementsButNth/README.es.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
let output = getAllElementsButNth(['a', 'b', 'c'], 1);
1111
console.log(output); // --> ['a', 'c']
1212
```
13+
14+
## 💡 Pista:
15+
16+
+ Una forma de hacer este ejercicio es con el método `splice()`, deberías investigarlo.

exercises/083-getAllElementsButNth/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
let output = getAllElementsButNth(['a', 'b', 'c'], 1);
1111
console.log(output); // --> ['a', 'c']
1212
```
13+
14+
## 💡 Hint:
15+
16+
+ One way to do this exercise is with the method `splice()`, you should search about it.

exercises/083-getAllElementsButNth/solution.hide.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ function getAllElementsButNth(array, n) {
33
array.splice(n, 1);
44
return array
55
}
6+
7+
let output = getAllElementsButNth(['a', 'b', 'c'], 1);
8+
console.log(output); // --> ['a', 'c']

exercises/084-areValidCredentials/README.es.md

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

33
## 📝 Instrucciones:
44

5-
1. Escribe una función llamada `areValidCredentials`. Dado un nombre y una contraseña, `areValidCredentials` retorna true si el nombre tiene más de 3 caracteres.
5+
1. Escribe una función llamada `areValidCredentials`. Dado un nombre y una contraseña, `areValidCredentials` retorna `true` si el nombre tiene más de 3 caracteres.
66

7-
2. La contraseña debe tener por lo menos 8 caracteres de lo contrario debe retornar false.
7+
2. La contraseña debe tener por lo menos 8 caracteres de lo contrario debe retornar `false`.
88

99
## 📎 Ejemplo:
1010

exercises/084-areValidCredentials/README.md

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

55
1. Write a function called `areValidCredentials`. Given a name and a password, `areValidCredentials`, returns `true` if the name is longer than 3 characters.
66

7-
2. The password must be at least 8 characters long, otherwise it should return false.
7+
2. The password must be at least 8 characters long, otherwise it should return `false`.
88

99
## 📎 Example:
1010

exercises/085-getIndexOf/README.es.md

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

55
1. Escribe una función llamada `getIndexOf`. Dado un caracter y un string, `getIndexOf` retorna la primera posición de dicho caracter en dicho string.
66

7-
## 📎 Ejemplo:
7+
## 📎 Ejemplo:
88

99
```js
1010
let output = getIndexOf('a', 'I am a hacker');
@@ -17,6 +17,6 @@ console.log(output); // --> 2
1717

1818
+ Cuando un string tiene un caracter que se repite, debería retornar el índice de su primera ocurrencia.
1919

20-
+ Si el caracter no existe en el string, debería retornar -1.
20+
+ Si el caracter no existe en el string, debería retornar `-1`.
2121

22-
+ No uses la función indexOf en tu implementación.
22+
+ No uses el método `indexOf()` en tu implementación.

exercises/085-getIndexOf/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ console.log(output); // --> 2
1717

1818
+ When a string contains more than one occurrence of a character, it should return the index of its first occurrence.
1919

20-
+ If the character does not exist in the string, it should return -1.
20+
+ If the character does not exist in the string, it should return `-1`.
2121

22-
+ Do not use the native indexOf function in your implementation.
22+
+ Do not use the native `indexOf()` function in your implementation.

exercises/091-countAllCharacters/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ console.log(output); // --> {b: 1, a: 3, n: 2}
1515

1616
+ El valor de cada key debería corresponder a la cantidad de veces que el caracter aparece en el string.
1717

18-
+ Si el string está vacío, `countAllCharacters` debería retornar un `objeto` vacío.
18+
+ Si el string está vacío, `countAllCharacters` debería retornar un objeto vacío `{}`.

exercises/091-countAllCharacters/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ console.log(output); // --> {b: 1, a: 3, n: 2}
1515

1616
+ The value of each key should be how many times each character appeared in the given string.
1717

18-
+ If given an empty string, `countAllCharacters` should return an empty object.
18+
+ If given an empty string, `countAllCharacters` should return an empty object `{}`.

exercises/091-countAllCharacters/solution.hide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function countAllCharacters(str) {
44
return {}
55
}
66

7-
obj = {}
7+
let obj = {}
88

99
for(let i = 0; i < str.length; i++) {
1010
if(obj[str[i]]) {

exercises/092-getElementsGreaterThanTenAtProperty/README.es.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ console.log(output); // --> [20, 30]
1616

1717
## 💡 Pistas:
1818

19-
+ Si el array está vacío, debería retornar un array vacío.
19+
+ Si el array está vacío, debería retornar un array vacío `[]`.
2020

21-
+ Si el array no contiene ningún elemento mayor a 10, debería retornar un array vacío.
21+
+ Si el array no contiene ningún elemento mayor a 10, debería retornar un array vacío `[]`.
2222

23-
+ Si la propiedad en esa key dada no es un array, debería retornar un array vacío.
23+
+ Si la propiedad en esa key dada no es un array, debería retornar un array vacío `[]`.
2424

25-
+ Si no hay ninguna propiedad en dicha key, debería retornar un array vacío.
25+
+ Si no hay ninguna propiedad en dicha key, debería retornar un array vacío `[]`.

exercises/092-getElementsGreaterThanTenAtProperty/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ console.log(output); // --> [20, 30]
1616

1717
## 💡 Hints:
1818

19-
+ If the array is empty, it should return an empty array.
19+
+ If the array is empty, it should return an empty array `[]`.
2020

21-
+ If the array contains no elements greater than 10, it should return an empty array.
21+
+ If the array contains no elements greater than 10, it should return an empty array `[]`.
2222

23-
+ If the property at the given key is not an array, it should return an empty array.
23+
+ If the property at the given key is not an array, it should return an empty array `[]`.
2424

25-
+ If there is no property at the key, it should return an empty array.
25+
+ If there is no property at the key, it should return an empty array `[]`.

exercises/093-removeElement/README.es.md

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

33
## 📝 Instrucciones:
44

5-
1. Escribe una función llamada `removeElement`. Dado un array de elementos y un parámetro con el item que se va a eliminar, `removeElement` retorna un array que contiene los items de dicho array que no coinciden con el parámetro "por eliminar".
5+
1. Escribe una función llamada `removeElement`. Dado un array de elementos y un parámetro con el item que se va a eliminar, `removeElement` retorna un **NUEVO** array que contiene los items de dicho array que no coinciden con el parámetro "por eliminar".
66

77
## 📎 Ejemplo:
88

@@ -13,6 +13,4 @@ console.log(output); // --> [1, 3, 1]
1313

1414
## 💡 Pistas:
1515

16-
+ Si todos los elementos coinciden, debería retornar un array vacío.
17-
18-
+ Si le pasamos un array vacío, debería retornar un array vacío.
16+
+ Deberías familiarizarte con el método `filter()` [Más información...](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)

exercises/093-removeElement/README.md

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

33
## 📝 Instructions:
44

5-
1. Write a function called `removeElement`. Given an array of elements and a `discarder` parameter, `removeElement` returns an array containing the items in the given array that do not match the `discarder` parameter.
5+
1. Write a function called `removeElement`. Given an array of elements and a `discarder` parameter, `removeElement` returns a **NEW** array containing the items in the given array that do not match the `discarder` parameter.
66

77
## 📎 Example:
88

@@ -13,6 +13,4 @@ console.log(output); // --> [1, 3, 1]
1313

1414
## 💡 Hints:
1515

16-
+ If all the elements match, it should return an empty array.
17-
18-
+ If an empty array is passed in, it should return an empty array.
16+
+ You should be familiar with the method `filter()` [More info here...](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
// Write your function here
22
function removeElement(arr, n) {
3-
let newArr = []
4-
5-
for(let i = 0; i < arr.length; i++) {
6-
if (arr[i] != n) {
7-
newArr.push(arr[i])
8-
}
9-
}
10-
return newArr
3+
return arr.filter((element) => element !== n);
114
}

exercises/097-keep/README.es.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ console.log(output); // --> [2, 2]
1313

1414
## 💡 Pista:
1515

16+
+ Deberías familiarizarte con el método `filter()` [Más información...](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
17+
1618
+ Si no coincide ningún elemento, la función `keep` debería retornar un array vacío `[]`.

exercises/097-keep/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ console.log(output); // --> [2, 2]
1313

1414
## 💡 Hint:
1515

16-
- If no elements match, the function `keep` should return an empty array `[]`.
16+
+ You should be familiar with the method `filter()` [More info here...](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
17+
18+
+ If no elements match, the function `keep` should return an empty array `[]`.

exercises/097-keep/solution.hide.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
// Write your function here
2-
function keep(arr, element) {
3-
let newArr = []
4-
5-
arr.forEach(e => {
6-
if(e == element) {
7-
newArr.push(e)
8-
}
9-
})
10-
11-
return newArr;
2+
function keep(arr, keeper) {
3+
return arr.filter((element) => element === keeper);
124
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
function getEvenLengthWordsAtProperty(obj, key) {
22
// your code here
3-
if (!obj[key] || !Array.isArray(obj[key])) {
4-
return []
5-
} else {
6-
let aux = []
7-
obj[key].map(e => {
8-
e.length % 2 == 0 ? aux.push(e) : null
9-
})
10-
return aux;
3+
if (!Array.isArray(obj[key])) {
4+
return [];
115
}
6+
7+
return obj[key].filter(word => word.length % 2 === 0);
128
}
9+
10+
let obj = {
11+
key: ['a', 'long', 'game']
12+
};
13+
let output = getEvenLengthWordsAtProperty(obj, 'key');
14+
console.log(output); // --> ['long', 'game']

exercises/102-filterOddLengthWords/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function filterOddLengthWords(words) {
22
// your code here
3+
34
}
45

56
let output = filterOddLengthWords(['there', 'it', 'is', 'now']);

exercises/103-getSquaredElementsAtProperty/README.es.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ console.log(output); // --> [4, 1, 25]
1616

1717
## 💡 Pistas:
1818

19+
+ Para transformar elementos en un array investiga el método `map()`.
20+
1921
+ Si el array está vacío, debe retornar un array vacío `[]`.
2022

2123
+ Si la propiedad en la key dada no es un array, debe retornar un array vacío `[]`.

exercises/103-getSquaredElementsAtProperty/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ console.log(output); // --> [4, 1, 25]
1616

1717
## 💡 Hints:
1818

19-
* If the array is empty, it should return an empty array `[]`.
19+
+ To transform elements in an array search about the `map()` method.
2020

21-
* If the property at the given key is not an array, it should return an empty array `[]`.
21+
+ If the array is empty, it should return an empty array `[]`.
2222

23-
* If there is no property at the key, it should return an empty array `[]`.
23+
+ If the property at the given key is not an array, it should return an empty array `[]`.
24+
25+
+ If there is no property at the key, it should return an empty array `[]`.

exercises/108-getSmallestElementAtProperty/solution.hide.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
function getSmallestElementAtProperty(obj, key) {
22
// your code here
3-
if (!obj[key] || !Array.isArray(obj[key]) || obj[key].length < 1) return []
4-
else {
5-
let aux = 999999999999999999
6-
obj[key].map(item => item < aux ? aux = item : null)
7-
return aux
3+
if (!Array.isArray(obj[key]) || (obj[key].length === 0)) {
4+
return [];
85
}
6+
7+
let arr = obj[key];
8+
let smallest = arr[0];
9+
10+
for (let i = 1; i < arr.length; i++) {
11+
if (arr[i] < smallest) {
12+
smallest = arr[i];
13+
}
14+
}
15+
16+
return smallest;
917
}
1018

1119
let obj = {

exercises/109-getLargestElementAtProperty/solution.hide.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
function getLargestElementAtProperty(obj, key) {
22
// your code here
3-
if (!obj[key] || !Array.isArray(obj[key]) || obj[key].length < 1) return []
4-
else {
5-
let aux = -999999999999999999
6-
obj[key].map(item => item > aux ? aux = item : null)
7-
return aux
3+
if (!Array.isArray(obj[key]) || (obj[key].length === 0)) {
4+
return [];
85
}
6+
7+
let arr = obj[key];
8+
let largest = arr[0];
9+
10+
for (let i = 1; i < arr.length; i++) {
11+
if (arr[i] > largest) {
12+
largest = arr[i];
13+
}
14+
}
15+
16+
return largest;
917
}
1018

1119
let obj = {

0 commit comments

Comments
 (0)