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.
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+
});

0 commit comments

Comments
 (0)