Skip to content

Commit 9cdc105

Browse files
authored
Merge pull request #137 from josemoracard/jose4-07.2-letter-counter
exercises 07.2-letter-counter to 14-divide-and-conquer
2 parents ea6cf33 + 9306d71 commit 9cdc105

Some content is hidden

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

53 files changed

+285
-289
lines changed

exercises/07.2-Letter-Counter/README.es.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# `07.2` Contador de letras
1+
# `07.2` Letter Counter
22

33
Nuestro cliente necesita un programa que cuente las repeticiones de las letras en un string dado. Sé que es extraño, pero es muy testarudo ¡Lo necesitamos lo antes posible!
44

5-
## :pencil: Instrucciones:
5+
## 📝 Instrucciones:
66

77
1. Crea un objeto donde las letras son las propiedades y los valores son el número de veces que esa letra se repite en toda la cadena.
88

@@ -14,7 +14,7 @@ const word = "Hello World";
1414
// Debería imprimir en la consola { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
1515
```
1616

17-
## :bulb: Pista:
17+
## 💡 Pistas:
1818

1919
+ Recorre todo el string (usa un bucle).
2020

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
---
2-
32
tutorial: https://www.youtube.com/watch?v=oLTidCuisew
4-
53
---
64

75
# `07.2` Letter Counter
86

9-
Our customer needs a program that counts the number of occurences of each letter in a given string. I know that's weird, but they are very adamant. We need this asap!
7+
Our customer needs a program that counts the number of occurrences of each letter in a given string. I know that's weird, but they are very adamant. We need this asap!
108

11-
## :pencil: Instructions:
9+
## 📝 Instructions:
1210

1311
1. Create an object where the letters are the properties and the values are the number of times that letter is repeated throughout the string.
1412

@@ -20,16 +18,16 @@ const word = "Hello World";
2018
// The console should print { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 }
2119
```
2220

23-
## :bulb: Hint
21+
## 💡 Hints:
2422

2523
+ Loop the entire string.
2624

27-
+ On every iteration check if the object `counts` has the letter initialized as a property.
25+
+ On every iteration, check if the object `counts` has the letter initialized as a property.
2826

2927
+ If the letter has not been initialized, then do it and set its value equal to 1 (first time found).
3028

31-
+ If it was already initialized just increment the property value by one.
29+
+ If it was already initialized, just increment the property value by one.
3230

3331
+ Remember to ignore white spaces in the string.
3432

35-
+ You should lower case all letters to have an accurate count of all letters regardless of casing of the letter.
33+
+ To accurately count all letters, regardless of their casing, you should convert all letters to lowercase.

exercises/07.2-Letter-Counter/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let par = "Lorem ipsum dolor sit amet consectetur adipiscing elit Curabitur eget bibendum turpis Curabitur scelerisque eros ultricies venenatis mi at tempor nisl Integer tincidunt accumsan cursus"
22
let counts = {};
33

4-
// your code here
4+
// Your code here
55

6-
console.log(counts);
6+
console.log(counts);
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
let par = "Lorem ipsum dolor sit amet consectetur adipiscing elit Curabitur eget bibendum turpis Curabitur scelerisque eros ultricies venenatis mi at tempor nisl Integer tincidunt accumsan cursus"
22
let counts = {};
33

4-
// your code here
5-
for(let i in par){
4+
// Your code here
5+
for(let i in par) {
66
const letter = par[i].toLowerCase();
7-
console.log(letter);
87
if(letter == " ") continue;
9-
else if(counts[letter] == undefined){
10-
console.log("Found "+letter+" for the first time")
8+
else if(counts[letter] == undefined) {
119
counts[letter] = 1;
1210
}
13-
else{
14-
console.log("Found "+letter+" more than once")
11+
else {
1512
counts[letter] = counts[letter] + 1;
16-
1713
}
1814
}
1915

20-
console.log(counts);
16+
console.log(counts);

exercises/07.2-Letter-Counter/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ it('You have to use the console.log function once, at the end of the exercise',
1313
expect(console.log.mock.calls.length).toBe(1);
1414
});
1515

16-
it('Use a for loop', function () {
16+
it('Use a "for" loop', function () {
1717
const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8');
1818
expect(app_content).toMatch(/for(\s*)\(/);
1919
});
@@ -37,4 +37,4 @@ it('Create the object with the letter counts like { a: 1, b: 4, ... }', function
3737
}
3838

3939
expect(counts).toEqual(_counts);
40-
});
40+
});
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# `07.3` Invierte el Array
1+
# `07.3` Flip Array
22

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

5-
1. Usando un bucle `for`, invierte el arreglo o array `arr` e imprime el nuevo arreglo o array en la consola.
5+
1. Usando un bucle `for`, invierte el array `arr` e imprime el nuevo array en la consola.
66

77
Por ejemplo:
88

99
```js
10-
array inicial: [45, 67, 87, 23, 5, 32, 60]; array array final : [60, 32, 5 , 23, 87, 67, 45];
10+
Initial array: [45, 67, 87, 23, 5, 32, 60];
11+
Final array: [60, 32, 5, 23, 87, 67, 45];
1112
```
1213

13-
## :bulb: Pista
14+
## 💡 Pistas:
1415

1516
+ Debes recorrer todo el arreglo [desde el final hasta el principio](https://stackoverflow.com/questions/1340589/are-loops-really-faster-in-reverse).
1617

17-
+ En cada bucle, inserta todos los elementos (a
18-
medida que avanza) en un nuevo array o arreglo, este será tu arreglo invertido.
18+
+ En cada bucle, inserta todos los elementos (a medida que avanza) en un nuevo array, este será tu arreglo invertido. ¿Qué otros métodos puedes usar además de `push()`?

exercises/07.3-Flip-Array/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ tutorial: https://www.youtube.com/watch?v=Snn7OtZY370
44

55
# `07.3` Flip Array
66

7-
## :pencil: Instructions:
7+
## 📝 Instructions:
88

99
1. Using a `for` loop, invert the `arr` array and print the new array on the console.
1010

1111
For example:
1212

1313
```js
14-
Initial array: [45, 67, 87, 23, 5, 32, 60];
15-
Final array: [60, 32, 5 , 23, 87, 67, 45];
14+
Initial array: [45, 67, 87, 23, 5, 32, 60];
15+
Final array: [60, 32, 5, 23, 87, 67, 45];
1616
```
1717

18-
## :bulb: Hint
18+
## 💡 Hints:
1919

20-
+ You should loop the entire array [from the end to the beggining](https://stackoverflow.com/questions/1340589/are-loops-really-faster-in-reverse).
20+
+ You should loop the entire array [from the end to the beginning](https://stackoverflow.com/questions/1340589/are-loops-really-faster-in-reverse).
2121

22-
+ On each loop push all the items (as you go) into a new array, this will be your flipped array. What other methods can you use besides `push()`?
22+
+ On each loop, push all the items (as you go) into a new array, this will be your flipped array. What other methods can you use besides `push()`?

exercises/07.3-Flip-Array/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
let arr = [45,67,87,23,5,32,60];
22

3-
//Your code here.
3+
// Your code here
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
let arr = [45,67,87,23,5,32,60];
22

3-
//Your code here.
3+
// Your code here
44
let flippedArray = []
5-
for(let i = arr.length - 1; i>= 0;i--){
5+
for(let i = arr.length - 1; i >= 0; i--) {
66
let item = arr[i];
77
flippedArray.push(item);
88
}
9-
console.log(flippedArray)
9+
10+
console.log(flippedArray)

exercises/07.3-Flip-Array/tests.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,23 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
99
let reverse = Array.prototype.reverse;
1010
Array.prototype.reverse = jest.fn(function(){ return this; });
1111

12-
it('Use the console.log function once to print the new array with the types on the console', function () {
12+
it('Use the console.log function once, at the end of the exercise', function () {
1313
const app = require('./app.js');
1414
expect(console.log.mock.calls.length).toBe(1);
1515
});
1616

17-
it("Use the typeof function inside the loop", function () {
18-
const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8');
19-
expect(app_content).not.toMatch(/\.typeof/);
20-
});
21-
22-
it('There needs to be a variable called arr with the original array', function () {
17+
it('There needs to be a variable called "arr" with the original array', function () {
2318
const _app = rewire('./app.js');
2419
const variable = _app.__get__('arr');
2520
expect(variable).toBeTruthy();
2621
});
2722

28-
it('Loop the array in a reverse order and console.log all of its item', function () {
23+
it('Loop the array in a reverse order and console.log all of its items', function () {
2924
const _app = rewire('./app.js');
3025
const variable = _app.__get__('arr');
3126
let inverted = [];
3227
for(let i = variable.length-1; i>=0;i--){
3328
inverted.push(variable[i]);
3429
}
3530
expect(_buffer).toMatch(inverted.map(n => n).join(","));
36-
});
31+
});
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# `08.01` Array mixto
1+
# `08.1` Mixed Array
22

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

5-
1. Escribe una función que imprima un arreglo en la consola que contenga los tipos de valores (data-types) que contiene el array `mix` en cada posición.
5+
1. Usando un bucle, imprime un nuevo array en la consola que contenga los tipos de valores (data-types) que contiene el array `mix` en cada posición.
66

7-
### Resultado esperado:
7+
## 💻 Resultado esperado:
88

99
```js
1010
[
@@ -15,14 +15,14 @@
1515
]
1616
```
1717

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

2020
+ Crea un nuevo arreglo vacío.
2121

2222
+ Recorre el arreglo original mediante un bucle.
2323

24-
+ En cada bucle, obten el tipo de elemento utilizando la función `typeof`.
24+
+ En cada bucle, obtén el tipo de elemento utilizando la función `typeof`.
2525

26-
+ Como la función `typeof` devuelve un string, puedes insertar(push) ese string en el nuevo arreglo(array).
26+
+ Como la función `typeof` devuelve un string, puedes insertar(push) ese string en el nuevo arreglo.
2727

28-
+ Cuando finalice el bucle o loop, debes haber encontrado todos los tipos de elementos del arreglo o array original y haberlos insertados(push) en el nuevo arreglo.
28+
+ Cuando finalice el bucle, debes haber encontrado todos los tipos de elementos del arreglo original y haberlos insertado(push) en el nuevo arreglo.

exercises/08.1-Mixed-array/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
tutorial: https://www.youtube.com/watch?v=3o02odJhieo
33
---
44

5-
# `08.01` Mixed Array
5+
# `08.1` Mixed Array
66

7-
## :pencil: Instructions:
7+
## 📝 Instructions:
88

9-
1. Write a function that prints in the console a new array that contains all the types of data that the array `mix` contains in each position.
9+
1. Using a loop, print in the console a new array that contains all the types of data that the array `mix` contains in each position.
1010

11-
### Expected Result:
11+
## 💻 Expected Result:
1212

1313
```js
1414
[
@@ -19,14 +19,14 @@ tutorial: https://www.youtube.com/watch?v=3o02odJhieo
1919
]
2020
```
2121

22-
## :bulb: Hints:
22+
## 💡 Hints:
2323

2424
+ Create a new empty array.
2525

2626
+ Loop the original array.
2727

28-
+ On every loop get the type of the item using the `typeof` function.
28+
+ On every loop, get the type of the item using the `typeof` function.
2929

30-
+ Since the `typeof` function return a string you can push that string to the new array.
30+
+ Since the `typeof` function returns a string you can push that string to the new array.
3131

32-
+ when the loop finished, you should have all the types found on the original array pushed to the new array.
32+
+ When the loop is finished, you should have all the types found on the original array pushed to the new array.

exercises/08.1-Mixed-array/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
let mix = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}];
22

3-
//your code here
3+
// Your code here
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
let mix = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}];
22

3-
//your code here
3+
// Your code here
44
let newArray = [];
55
for (let i = 0; i < mix.length; i++) {
66
const item = mix[i];
77
newArray.push(typeof item)
8-
98
}
10-
console.log(newArray)
9+
10+
console.log(newArray)

exercises/08.1-Mixed-array/tests.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ it("Create a loop", function () {
1414
expect(app_content).toMatch(/for\s*/);
1515
});
1616

17-
it("Don't use the reverse function", function () {
18-
const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8');
19-
expect(app_content).not.toMatch(/\.reverse(\s*)\(/);
20-
});
21-
2217
it('Use the console.log function once to print the newArray on the console', function () {
2318
const app = require('./app.js');
2419
expect(console.log.mock.calls.length).toBe(1);
2520
});
2621

27-
it('There needs to be a variable called mix with the original array', function () {
22+
it('There needs to be a variable called "mix" with the original array', function () {
2823
const _app = rewire('./app.js');
2924
const variable = _app.__get__('mix');
3025
expect(variable).toBeTruthy();
@@ -45,4 +40,4 @@ it('Loop the array and console.log all of its item types', function () {
4540
let _test = myFunc()
4641
expect(_buffer).toMatch(_test.map(n => n).join(","));
4742
// expect(_buffer).toMatch(inverted.map(n => n).join(","));
48-
});
43+
});

exercises/08.2-Count-On/README.es.md

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

33
Como viste en el último ejercicio, tu arreglo o array puede tener una mezcla de tipos de datos.
44

5-
## :pencil: Instrucciones
5+
## 📝 Instrucciones:
66

77
1. Agrega todos los elementos con tipo de dato objeto dentro del array `hello`.
88

9-
Aquí puedes ver cómo imprimir TODOS los elementos.
9+
Aquí puedes ver cómo imprimir los tipos de elementos:
1010

1111
```js
1212
let myArray = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}];
1313

14-
for(let index = 0; index < myArray.length; index++){
15-
let item = myArray[index];
14+
for(let i = 0; i < myArray.length; i++) {
15+
let item = myArray[i];
1616
console.log(typeof(item))
1717
}
1818
```
1919

20-
## :bulb: Pista
20+
> Nota: Te darás cuenta que cuando verificas el tipo de dato de un array, te devolverá que es un `'object'`. Puedes investigar el por qué en Google o proceder con el ejercicio como de costumbre.
21+
22+
## 💡 Pistas:
2123

2224
+ Recorre el array dado con un loop.
2325

24-
+ Agrega una condición dentro del bucle(loop) que verifique que el elemento sea un objeto.
26+
+ Agrega una condición dentro del bucle que verifique que el elemento sea un objeto.
2527

2628
+ Si el elemento es un objeto, se agrega al arreglo `hello`.
2729

28-
+ Usa `console.log()`para imprimir el array `hello` en la consola.
30+
+ Usa `console.log()` para imprimir el array `hello` en la consola.

0 commit comments

Comments
 (0)