Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions exercises/21-Russian_Roulette/README.es.md

This file was deleted.

19 changes: 0 additions & 19 deletions exercises/21-Russian_Roulette/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions exercises/21-Russian_Roulette/app.js

This file was deleted.

18 changes: 0 additions & 18 deletions exercises/21-Russian_Roulette/solution.hide.js

This file was deleted.

39 changes: 0 additions & 39 deletions exercises/21-Russian_Roulette/tests.js

This file was deleted.

46 changes: 46 additions & 0 deletions exercises/21-Your_first_array/README.es.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
tutorial: "https://www.youtube.com/watch?v=prIqHDmw5r0"
---

# `21` Tu Primer Array

Un array es una lista de valores. Los arrays son una de las estructuras de datos más importantes en programación porque nos permiten almacenar múltiples valores en una sola variable.

Los arrays se declaran con corchetes `[]` y pueden contener cualquier tipo de dato:

```js
let fruits = ["manzana", "plátano", "naranja"];
let numeros = [1, 2, 3, 4, 5];
let mixto = [1, "hola", true, 3.14];
```

Puedes acceder a cada elemento en un array usando su **índice** (posición). Recuerda que los índices comienzan en `0`:

```js
let fruits = ["manzana", "plátano", "naranja"];
console.log(fruits[0]); // "manzana"
console.log(fruits[1]); // "plátano"
console.log(fruits[2]); // "naranja"
```

## 📝 Instrucciones:

1. Crea un array llamado `colors` con al menos 3 nombres de colores como strings.
2. Usa `console.log()` para imprimir cada color accediendo por su posición de índice.
3. Imprime el array completo en la consola.

## Ejemplo:

```js
let animals = ["perro", "gato", "pájaro"];
console.log(animals[0]); // "perro"
console.log(animals[1]); // "gato"
console.log(animals[2]); // "pájaro"
console.log(animals); // ["perro", "gato", "pájaro"]
```

## 💡 Pista:

+ Recuerda: los índices de arrays comienzan en 0, ¡no en 1!
+ Puedes almacenar cualquier tipo de dato dentro de un array.

46 changes: 46 additions & 0 deletions exercises/21-Your_first_array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
tutorial: "https://www.youtube.com/watch?v=prIqHDmw5r0"
---

# `21` Your First Array

An array is a list of values. Arrays are one of the most important data structures in programming because they allow us to store multiple values in a single variable.

Arrays are declared with square brackets `[]` and can hold any type of data:

```js
let fruits = ["apple", "banana", "orange"];
let numbers = [1, 2, 3, 4, 5];
let mixed = [1, "hello", true, 3.14];
```

You can access each element in an array using its **index** (position). Remember that indices start at `0`:

```js
let fruits = ["apple", "banana", "orange"];
console.log(fruits[0]); // "apple"
console.log(fruits[1]); // "banana"
console.log(fruits[2]); // "orange"
```

## 📝 Instructions:

1. Create an array called `colors` with at least 3 color names as strings.
2. Use `console.log()` to print each color accessing it by its index position.
3. Print the array itself to the console.

## Example:

```js
let animals = ["dog", "cat", "bird"];
console.log(animals[0]); // "dog"
console.log(animals[1]); // "cat"
console.log(animals[2]); // "bird"
console.log(animals); // ["dog", "cat", "bird"]
```

## 💡 Hint:

+ Remember: array indexes start at 0, not 1!
+ You can store any type of data inside an array.

8 changes: 8 additions & 0 deletions exercises/21-Your_first_array/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//Create an array with at least 3 colors
let colors = [];

//access and print each color by its index

//print the array
//your code here

10 changes: 10 additions & 0 deletions exercises/21-Your_first_array/solution.hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//Create an array with at least 3 colors
let colors = ["red", "blue", "green"];

//access and print each color by its index
console.log(colors[0]);
console.log(colors[1]);
console.log(colors[2]);

//print the array
console.log(colors);
32 changes: 32 additions & 0 deletions exercises/21-Your_first_array/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

const fs = require('fs');
const path = require('path');

jest.dontMock('fs');
let _buffer = "";
let _log = console.log;

global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");

describe('Array exercise', function () {
afterEach(() => { jest.resetModules(); });

it('Should have an array called "colors"', function () {
const appPath = path.join(__dirname, './app.js');
const appContent = fs.readFileSync(appPath, 'utf8');
expect(appContent).toMatch(/let\s+colors\s*=\s*\[/);
});

it('Should print at least 3 elements from the colors array', function () {
_buffer = "";
const { colors } = require('./app.js');
const logs = _buffer.trim().split('\n');
expect(logs.length).toBeGreaterThanOrEqual(3);
});

it('Should print the array itself', function () {
_buffer = "";
require('./app.js');
expect(_buffer).toMatch(/,/); // arrays have commas when printed
});
});
49 changes: 49 additions & 0 deletions exercises/22-Array_methods/README.es.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
tutorial: "https://www.youtube.com/watch?v=prIqHDmw5r0"
---

# `22` Métodos de Arrays

Los arrays tienen muchos métodos incorporados que nos permiten manipularlos. Los más comunes son:

- **`push()`**: Añade uno o más elementos al final del array
- **`pop()`**: Elimina el último elemento del array
- **`shift()`**: Elimina el primer elemento del array
- **`unshift()`**: Añade uno o más elementos al principio del array
- **`length`**: Propiedad que devuelve el número de elementos en un array

```js
let fruits = ["manzana", "plátano"];
fruits.push("naranja"); // fruits es ahora ["manzana", "plátano", "naranja"]
console.log(fruits.length); // 3

let lastFruit = fruits.pop(); // elimina "naranja", lastFruit = "naranja"
console.log(fruits); // ["manzana", "plátano"]

fruits.unshift("uva"); // fruits es ahora ["uva", "manzana", "plátano"]
let firstFruit = fruits.shift(); // elimina "uva", firstFruit = "uva"
```

## 📝 Instrucciones:

1. Crea un array llamado `students` con 3 nombres de estudiantes.
2. Añade un nuevo nombre de estudiante al final usando `push()`.
3. Elimina el primer estudiante usando `shift()`.
4. Imprime la longitud del array.
5. Imprime el array final.

## Ejemplo:

```js
let team = ["Alice", "Bob"];
team.push("Charlie"); // ["Alice", "Bob", "Charlie"]
team.shift(); // ["Bob", "Charlie"]
console.log(team.length); // 2
console.log(team); // ["Bob", "Charlie"]
```

## 💡 Pista:

+ Los métodos son funciones que pertenecen a objetos. ¡Los arrays también son objetos!
+ `push()` y `unshift()` añaden elementos, mientras que `pop()` y `shift()` los eliminan.

49 changes: 49 additions & 0 deletions exercises/22-Array_methods/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
tutorial: "https://www.youtube.com/watch?v=prIqHDmw5r0"
---

# `22` Array Methods

Arrays have many built-in methods that allow us to manipulate them. The most common ones are:

- **`push()`**: Adds one or more elements to the end of an array
- **`pop()`**: Removes the last element from an array
- **`shift()`**: Removes the first element from an array
- **`unshift()`**: Adds one or more elements to the beginning of an array
- **`length`**: Property that returns the number of elements in an array

```js
let fruits = ["apple", "banana"];
fruits.push("orange"); // fruits is now ["apple", "banana", "orange"]
console.log(fruits.length); // 3

let lastFruit = fruits.pop(); // removes "orange", lastFruit = "orange"
console.log(fruits); // ["apple", "banana"]

fruits.unshift("grape"); // fruits is now ["grape", "apple", "banana"]
let firstFruit = fruits.shift(); // removes "grape", firstFruit = "grape"
```

## 📝 Instructions:

1. Create an array called `students` with 3 student names.
2. Add a new student name to the end using `push()`.
3. Remove the first student using `shift()`.
4. Print the length of the array.
5. Print the final array.

## Example:

```js
let team = ["Alice", "Bob"];
team.push("Charlie"); // ["Alice", "Bob", "Charlie"]
team.shift(); // ["Bob", "Charlie"]
console.log(team.length); // 2
console.log(team); // ["Bob", "Charlie"]
```

## 💡 Hint:

+ Methods are functions that belong to objects. Arrays are objects too!
+ `push()` and `unshift()` add elements, while `pop()` and `shift()` remove them.

14 changes: 14 additions & 0 deletions exercises/22-Array_methods/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//Create an array called students with 3 names
let students = [];

//Add a new student name to the end using push()
//your code here

//Remove the first student using shift()
//your code here

//Print the length of the array
//your code here

//Print the final array
//your code here
14 changes: 14 additions & 0 deletions exercises/22-Array_methods/solution.hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//Create an array called students with 3 names
let students = ["Maria", "Juan", "Pedro"];

//Add a new student name to the end using push()
students.push("Ana");

//Remove the first student using shift()
students.shift();

//Print the length of the array
console.log(students.length);

//Print the final array
console.log(students);
Loading