├── .gitignore ├── .husky └── commit-msg ├── CHANGELOG.md ├── README.md ├── commitlint.config.cjs ├── package-lock.json ├── package.json ├── src ├── challenge-01 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-02 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-03 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-04 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-05 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-06 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-07 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-08 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-09 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-10 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-11 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-12 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-13 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-14 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-15 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-16 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-17 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-18 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-19 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-20 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-21 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-22 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-23 │ ├── README.md │ ├── solution.js │ └── solution.test.js ├── challenge-24 │ ├── README.md │ ├── solution.js │ └── solution.test.js └── challenge-25 │ ├── README.md │ ├── solution.js │ └── solution.test.js └── vite.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx --no -- commitlint --edit 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 (2022-12-23) 2 | 3 | * feat: Add solution challenge 01 ([f777bdf](https://github.com/NeftXx/adventjs-retos/commit/f777bdf)) 4 | * feat: Add solution challenge 02 ([ae0a74d](https://github.com/NeftXx/adventjs-retos/commit/ae0a74d)) 5 | * feat: Add solution challenge 03 ([3c57a62](https://github.com/NeftXx/adventjs-retos/commit/3c57a62)) 6 | * feat: Add solution challenge 04 ([258ff48](https://github.com/NeftXx/adventjs-retos/commit/258ff48)) 7 | * feat: Add solution challenge 05 ([6dbd9b2](https://github.com/NeftXx/adventjs-retos/commit/6dbd9b2)) 8 | * feat: Add solution challenge 06 ([cb79e64](https://github.com/NeftXx/adventjs-retos/commit/cb79e64)) 9 | * feat: Add solution challenge 07 ([dd139d3](https://github.com/NeftXx/adventjs-retos/commit/dd139d3)) 10 | * feat: Add solution challenge 08 ([a8ba071](https://github.com/NeftXx/adventjs-retos/commit/a8ba071)) 11 | * feat: Add solution challenge 09 ([ed83ba2](https://github.com/NeftXx/adventjs-retos/commit/ed83ba2)) 12 | * feat: Add solution challenge 10 ([281ab4f](https://github.com/NeftXx/adventjs-retos/commit/281ab4f)) 13 | * feat: Add solution challenge 11 ([8682c16](https://github.com/NeftXx/adventjs-retos/commit/8682c16)) 14 | * feat: Add solution challenge 12 ([0f3044d](https://github.com/NeftXx/adventjs-retos/commit/0f3044d)) 15 | * feat: Add solution challenge 13 ([4fd28c7](https://github.com/NeftXx/adventjs-retos/commit/4fd28c7)) 16 | * feat: Add solution challenge 14 ([2202937](https://github.com/NeftXx/adventjs-retos/commit/2202937)) 17 | * feat: Add solution challenge 15 ([f9839df](https://github.com/NeftXx/adventjs-retos/commit/f9839df)) 18 | * feat: Add solution challenge 16 ([f67951f](https://github.com/NeftXx/adventjs-retos/commit/f67951f)) 19 | * feat: Add solution challenge 16 ([2207d7b](https://github.com/NeftXx/adventjs-retos/commit/2207d7b)) 20 | * feat: Add solution challenge 17 ([8c07d04](https://github.com/NeftXx/adventjs-retos/commit/8c07d04)) 21 | * feat: Add solution challenge 18 ([b816b18](https://github.com/NeftXx/adventjs-retos/commit/b816b18)) 22 | * feat: Add solution challenge 19 ([5381239](https://github.com/NeftXx/adventjs-retos/commit/5381239)) 23 | * feat: Add solution challenge 20 ([b2cbf33](https://github.com/NeftXx/adventjs-retos/commit/b2cbf33)) 24 | * feat: Add solution challenge 21 ([6986618](https://github.com/NeftXx/adventjs-retos/commit/6986618)) 25 | * feat: Add solution challenge 22 ([f385888](https://github.com/NeftXx/adventjs-retos/commit/f385888)) 26 | * feat: Add solution challenge 22 ([1b58a40](https://github.com/NeftXx/adventjs-retos/commit/1b58a40)) 27 | * feat: Add solution challenge 23 ([46ebe19](https://github.com/NeftXx/adventjs-retos/commit/46ebe19)) 28 | * feat: Add solution challenge 24 ([417baca](https://github.com/NeftXx/adventjs-retos/commit/417baca)) 29 | * feat: Add solution challenge 25 ([e657d0b](https://github.com/NeftXx/adventjs-retos/commit/e657d0b)) 30 | * feat: Init challenges ([77e00e9](https://github.com/NeftXx/adventjs-retos/commit/77e00e9)) 31 | * feat: solution of challenge 1 ([6a33886](https://github.com/NeftXx/adventjs-retos/commit/6a33886)) 32 | * refactor: adventJS challenge changes ([c5aa0f0](https://github.com/NeftXx/adventjs-retos/commit/c5aa0f0)) 33 | * chore: add CHANGELOG.md ([7e3b33b](https://github.com/NeftXx/adventjs-retos/commit/7e3b33b)) 34 | * chore: change extension of commitlint.config.js ([40d0388](https://github.com/NeftXx/adventjs-retos/commit/40d0388)) 35 | * chore: conventional commit configuration ([3b67488](https://github.com/NeftXx/adventjs-retos/commit/3b67488)) 36 | * Update: Add new examples for challenge 23 ([2937c92](https://github.com/NeftXx/adventjs-retos/commit/2937c92)) 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Retos de AdventJS 2 | 3 | Aquí almacenaré todos los retos de [AdventJS](https://adventjs.dev) resueltos por mí. 4 | 5 | **¿Qué es AdventJS?** 6 | 7 | AdventJS es una iniciativa de [@midudev](https://midu.dev) basada en Advent of Code que consiste en resolver un reto diario cada día de diciembre hasta el día 25. 8 | -------------------------------------------------------------------------------- /commitlint.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'] 3 | }; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adventjs-retos", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "type": "module", 7 | "scripts": { 8 | "test": "vitest", 9 | "test:ui": "vitest --ui", 10 | "test:run": "vitest run", 11 | "prepare": "husky install" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "devDependencies": { 17 | "@commitlint/cli": "17.3.0", 18 | "@commitlint/config-conventional": "17.3.0", 19 | "@vitest/ui": "0.26.2", 20 | "husky": "8.0.2", 21 | "vite": "4.0.3", 22 | "vitest": "0.26.2" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/challenge-01/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Este año los elfos han comprado una máquina que envuelve regalos. Pero… ¡no viene programada! Necesitamos crear un algoritmo que le ayude en la tarea. 4 | 5 | A la máquina se le pasa un array con los regalos. Cada regalo es un string. Necesitamos que la máquina envuelva cada regalo en papel de regalo y lo coloque en un array de regalos envueltos. 6 | 7 | El papel de regalo es el símbolo `*` y para envolver un regalo se coloca el símbolo `*` de forma que rodee totalmente al string por todos los lados. Por ejemplo: 8 | 9 | ```js 10 | const gifts = ['cat', 'game', 'socks']; 11 | const wrapped = wrapping(gifts); 12 | 13 | console.log(wrapped); 14 | /* [ 15 | "*****\n*cat*\n*****", 16 | "******\n*game*\n******", 17 | "*******\n*socks*\n*******" 18 | ] */ 19 | ``` 20 | 21 | Como ves, el papel de regalo envuelve el string. Por arriba y por abajo, para no dejar ningún hueco, las esquinas también están cubiertas por el papel de regalo. 22 | 23 | **Nota:** El carácter `\n` representa un salto de línea. 24 | 25 | **¡Ojo!** Asegúrate que pones el número correcto de `*` para envolver completamente el string. Pero no demasiados. Sólo los necesarios para cubrir el string. 26 | 27 | Ah, **y no modifiques (mutes) el array original.** 28 | -------------------------------------------------------------------------------- /src/challenge-01/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} gifts 3 | */ 4 | export function wrapping(gifts) { 5 | const ASTERISK = '*'; 6 | 7 | const createWrapper = (gift) => { 8 | const asteriskLength = gift.length + 2; 9 | const asterisk = ASTERISK.repeat(asteriskLength); 10 | 11 | return `${asterisk}\n*${gift}*\n${asterisk}`; 12 | }; 13 | 14 | const wrapped = gifts.map(createWrapper); 15 | 16 | return wrapped; 17 | } 18 | -------------------------------------------------------------------------------- /src/challenge-01/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { wrapping } from './solution.js'; 3 | 4 | test('it returns an array type', () => { 5 | const input = []; 6 | const output = wrapping(input); 7 | 8 | expect(Array.isArray(output)).toBe(true); 9 | }); 10 | 11 | test('verify wrapping(gifts)', () => { 12 | const expected = ['*****\n*cat*\n*****', '******\n*game*\n******', '*******\n*socks*\n*******']; 13 | const gifts = ['cat', 'game', 'socks']; 14 | const output = wrapping(gifts); 15 | 16 | expect(output).toEqual(expected); 17 | }); 18 | 19 | test('wrapping(["midu"])', () => { 20 | const expected = ['******\n*midu*\n******']; 21 | const input = ['midu']; 22 | const output = wrapping(input); 23 | 24 | expect(output).toEqual(expected); 25 | }); 26 | 27 | test('wrapping(["a"])', () => { 28 | const expected = ['***\n*a*\n***']; 29 | const input = ['a']; 30 | const output = wrapping(input); 31 | 32 | expect(output).toEqual(expected); 33 | }); 34 | 35 | test('wrapping an empty array should return an empty array', () => { 36 | const expected = []; 37 | const input = []; 38 | const output = wrapping(input); 39 | 40 | expect(output).toEqual(expected); 41 | }); 42 | -------------------------------------------------------------------------------- /src/challenge-02/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Un millonario ha comprado una red social y no trae buenas noticias. Ha anunciado **que cada vez que una jornada de trabajo se pierde por un día festivo**, habrá que compensarlo con **dos horas extra otro día de ese mismo año.** 4 | 5 | Obviamente la gente que trabaja en la empresa no le ha hecho ni pizca de gracia y están **preparando un programa que les diga el número de horas extras que harían** en el año si se aplicara la nueva norma. 6 | 7 | Al ser trabajo de oficina, su horario laboral es **de lunes a viernes**. Así que sólo tienes que preocuparte de los días festivos que caen en esos días. 8 | 9 | Dado un año y un array con las fechas de los días festivos, devuelve el número de horas extra que se harían ese año: 10 | 11 | ```js 12 | const year = 2022; 13 | const holidays = ['01/06', '04/01', '12/25']; // formato MM/DD 14 | 15 | // 01/06 es el 6 de enero, jueves. Cuenta. 16 | // 04/01 es el 1 de abril, un viernes. Cuenta. 17 | // 12/25 es el 25 de diciembre, un domingo. No cuenta. 18 | 19 | countHours(year, holidays); // 2 días -> 4 horas extra en el año 20 | ``` 21 | 22 | Cosas a tener en cuenta y consejos: 23 | 24 | - **El año puede ser bisiesto. Haz las comprobaciones que necesitas para ello, si fuese necesario.** 25 | - **Aunque el 31 de diciembre sea festivo, las horas extra se harán el mismo año y no el siguiente.** 26 | - **El método `Date.getDay()` te devuelve el día de la semana de una fecha. El 0 es domingo, el 1 es lunes, etc.** 27 | -------------------------------------------------------------------------------- /src/challenge-02/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * return the number of extra hours that would be done during that year 3 | * 4 | * @param {number} year 5 | * @param {string[]} holidays 6 | */ 7 | export function countHours(year, holidays) { 8 | const EXTRA_HOURS_BY_DAY = 2; 9 | 10 | const isWeekend = (holiday) => { 11 | const SUNDAY = 0; 12 | const SATURDAY = 6; 13 | const date = new Date(`${year}/${holiday}`); 14 | const valueDay = date.getDay(); 15 | return valueDay === SUNDAY || valueDay === SATURDAY; 16 | }; 17 | 18 | const numberOfHolidays = holidays.length; 19 | const numberOfHolidaysInWeekend = holidays.filter(isWeekend).length; 20 | const numberOfHolidaysInWeek = numberOfHolidays - numberOfHolidaysInWeekend; 21 | const extraHoursCurrentYear = numberOfHolidaysInWeek * EXTRA_HOURS_BY_DAY; 22 | 23 | return extraHoursCurrentYear; 24 | } 25 | -------------------------------------------------------------------------------- /src/challenge-02/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { countHours } from './solution.js'; 3 | 4 | test('it returns an number type', () => { 5 | const year = 2022; 6 | const holidays = []; 7 | const output = countHours(year, holidays); 8 | 9 | expect(typeof output).toBe('number'); 10 | }); 11 | 12 | test("verify countHours(2023, ['01/06', '04/01', '12/25'])", () => { 13 | const expected = 4; 14 | const year = 2023; 15 | const holidays = ['01/06', '04/01', '12/25']; 16 | const output = countHours(year, holidays); 17 | 18 | expect(output).toBe(expected); 19 | }); 20 | 21 | test("verify countHours(2022, ['01/06', '04/01', '12/25'])", () => { 22 | const expected = 4; 23 | const year = 2022; 24 | const holidays = ['01/06', '04/01', '12/25']; 25 | const output = countHours(year, holidays); 26 | 27 | expect(output).toBe(expected); 28 | }); 29 | 30 | test("verify countHours(1985, ['01/01', '01/06', '02/02', '02/17', '02/28', '06/03', '12/06', '12/25'])", () => { 31 | const expected = 10; 32 | const year = 1985; 33 | const holidays = ['01/01', '01/06', '02/02', '02/17', '02/28', '06/03', '12/06', '12/25']; 34 | const output = countHours(year, holidays); 35 | 36 | expect(output).toBe(expected); 37 | }); 38 | 39 | test("verify countHours(2000, ['01/01'])", () => { 40 | const expected = 0; 41 | const year = 2000; 42 | const holidays = ['01/01']; 43 | const output = countHours(year, holidays); 44 | 45 | expect(output).toBe(expected); 46 | }); 47 | -------------------------------------------------------------------------------- /src/challenge-03/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Tienes una caja de regalos de Navidad que Santa Claus quiere entregar a los niños. **Cada regalo está representado por una cadena**. Santa Claus tiene un trineo que puede llevar un **peso limitado**, y cada regalo dentro de la caja tiene un peso que es igual al número de letras en el nombre del regalo. 4 | 5 | Santa Claus también tiene una lista de renos que pueden ayudarlo a entregar los regalos. Cada reno tiene un límite de peso máximo que puede llevar. El **límite de peso máximo** de cada reno es **igual a dos veces el número de letras en su nombre.** 6 | 7 | Tu tarea es implementar una función `distributeGifts(packOfGifts`, reindeers) que recibe una caja de regalos y una lista de renos y devuelve el número máximo de cajas de estos regalos que Santa Claus puede entregar a los niños. Las cajas de regalos no se pueden dividir. 8 | 9 | ```js 10 | const packOfGifts = ['book', 'doll', 'ball']; 11 | const reindeers = ['dasher', 'dancer']; 12 | 13 | // el pack de regalos pesa 4 + 4 + 4 = 12 14 | // los renos pueden llevar (2 * 6) + (2 * 6) = 24 15 | // por lo tanto, Santa Claus puede entregar 2 cajas de regalos 16 | 17 | distributeGifts(packOfGifts, reindeers); // 2 18 | ``` 19 | 20 | Cosas a tener en cuenta: 21 | 22 | - **Las cajas de regalos no se pueden dividir.** 23 | 24 | - **Los nombres de los regalos y los renos siempre serán mayores que 0.** 25 | -------------------------------------------------------------------------------- /src/challenge-03/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} packOfGifts names of gifts 3 | * @param {string[]} reindeers names of reindeers 4 | */ 5 | export function distributeGifts(packOfGifts, reindeers) { 6 | const REINDEER_MULTIPLE = 2; 7 | const giftsNames = packOfGifts.join(''); 8 | const reindeersNames = reindeers.join(''); 9 | 10 | const totalGiftWeight = giftsNames.length; 11 | const totalReindeerWeightCapacity = reindeersNames.length * REINDEER_MULTIPLE; 12 | 13 | const numberOfPacks = Math.floor( 14 | totalReindeerWeightCapacity / totalGiftWeight 15 | ); 16 | 17 | return numberOfPacks; 18 | } 19 | -------------------------------------------------------------------------------- /src/challenge-03/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { distributeGifts } from './solution.js'; 3 | 4 | test('it returns an number type', () => { 5 | const packOfGifts = []; 6 | const reindeers = []; 7 | const output = distributeGifts(packOfGifts, reindeers); 8 | 9 | expect(typeof output).toBe('number'); 10 | }); 11 | 12 | test("verify distributeGifts(['a', 'b', 'c'], ['d', 'e'])", () => { 13 | const expected = 1; 14 | const packOfGifts = ['a', 'b', 'c']; 15 | const reindeers = ['d', 'e']; 16 | const output = distributeGifts(packOfGifts, reindeers); 17 | 18 | expect(output).toBe(expected); 19 | }); 20 | 21 | test("it should return 0 if reindeers can't carry any pack: distributeGifts(['videogames', 'console'], ['midu'])", () => { 22 | const expected = 0; 23 | const packOfGifts = ['videogames', 'console']; 24 | const reindeers = ['midu']; 25 | const output = distributeGifts(packOfGifts, reindeers); 26 | 27 | expect(output).toBe(expected); 28 | }); 29 | 30 | test("verify distributeGifts(['game', 'videoconsole', 'computer'], ['midudev', 'pheralb', 'codingwithdani', 'carlosble', 'blasco', 'facundocapua', 'madeval', 'memxd'])", () => { 31 | const expected = 5; 32 | const packOfGifts = ['game', 'videoconsole', 'computer']; 33 | const reindeers = ['midudev', 'pheralb', 'codingwithdani', 'carlosble', 'blasco', 'facundocapua', 'madeval', 'memxd']; 34 | const output = distributeGifts(packOfGifts, reindeers); 35 | 36 | expect(output).toBe(expected); 37 | }); 38 | 39 | test("verify distributeGifts(['music'], ['midudev', 'pheralb', 'codingwithdani', 'carlosble', 'blasco', 'facundocapua', 'madeval', 'memxd'])", () => { 40 | const expected = 26; 41 | const packOfGifts = ['music']; 42 | const reindeers = ['midudev', 'pheralb', 'codingwithdani', 'carlosble', 'blasco', 'facundocapua', 'madeval', 'memxd']; 43 | const output = distributeGifts(packOfGifts, reindeers); 44 | 45 | expect(output).toBe(expected); 46 | }); 47 | -------------------------------------------------------------------------------- /src/challenge-04/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Santa Claus necesita hacer una revisión de sus cajas de regalos para asegurarse de que puede empaquetarlas todas en su trineo. Cuenta con una serie de **cajas de diferentes tamaños, que se caracterizan por su longitud, anchura y altura.** 4 | 5 | Tu tarea es escribir **una función** que, **dada una lista de cajas con sus tamaños**, determine si es posible **empaquetar todas las cajas en una sola de manera que cada caja contenga a otra** (que a su vez contenga a otra, y así sucesivamente). 6 | 7 | Cada caja representa sus medidas con un objeto. Por ejemplo: `{l: 2, w: 3, h: 2}`. Esto significa que la caja tiene una longitud de 2, una anchura de 3 y una altura de 2. 8 | 9 | Una caja entra en otra caja si todos los lados de la primera son menores a los lados de la segunda. **Los elfos nos han dicho que las cajas no se pueden rotar**, así que no se puede poner una caja de 2x3x2 en una caja de 3x2x2. Veamos unos ejemplos: 10 | 11 | ```js 12 | fitsInOneBox([ 13 | { l: 1, w: 1, h: 1 }, 14 | { l: 2, w: 2, h: 2 } 15 | ]); // true 16 | ``` 17 | 18 | En el ejemplo anterior, la caja más pequeña entra en la caja más grande. Por lo tanto, es posible empaquetar todas las cajas en una sola. Ahora veamos un caso que no: 19 | 20 | ```js 21 | const boxes = [ 22 | { l: 1, w: 1, h: 1 }, 23 | { l: 2, w: 2, h: 2 }, 24 | { l: 3, w: 1, h: 3 } 25 | ]; 26 | 27 | fitsInOneBox(boxes); // false 28 | ``` 29 | 30 | En el ejemplo anterior, la caja más pequeña entra en la caja del medio, pero la caja del medio no entra en la caja más grande. Por lo tanto, no es posible empaquetar todas las cajas en una sola. 31 | 32 | Ten en cuenta que las cajas pueden no venir en orden: 33 | 34 | ```js 35 | const boxes = [ 36 | { l: 1, w: 1, h: 1 }, 37 | { l: 3, w: 3, h: 3 }, 38 | { l: 2, w: 2, h: 2 } 39 | ]; 40 | 41 | fitsInOneBox(boxes); // true 42 | ``` 43 | 44 | En el ejemplo anterior, la primer caja cabe en la tercera, y la tercera en la segunda. Por lo tanto, es posible empaquetar todas las cajas en una sola. 45 | 46 | Cosas a tener en cuenta: 47 | 48 | - **Las cajas no se pueden rotar ya que los elfos nos han dicho que la máquina no está preparada.** 49 | - **Las cajas pueden venir desordenadas de tamaño.** 50 | - **Las cajas no son siempre cuadradas, pueden ser rectangulares.** 51 | -------------------------------------------------------------------------------- /src/challenge-04/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Array<{l: number, w: number, h: number }>} boxes 3 | */ 4 | export function fitsInOneBox(boxes) { 5 | return false; 6 | } 7 | -------------------------------------------------------------------------------- /src/challenge-04/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { fitsInOneBox } from './solution.js'; 3 | 4 | test('it returns an boolean type', () => { 5 | const boxes = [ 6 | { l: 1, w: 1, h: 1 }, 7 | { l: 2, w: 2, h: 2 } 8 | ]; 9 | const output = fitsInOneBox(boxes); 10 | 11 | expect(typeof output).toBe('boolean'); 12 | }); 13 | 14 | test('verify test 2', () => { 15 | const expected = false; 16 | const boxes = [ 17 | { l: 1, w: 1, h: 10 }, 18 | { l: 3, w: 3, h: 12 }, 19 | { l: 2, w: 2, h: 1 } 20 | ]; 21 | const output = fitsInOneBox(boxes); 22 | 23 | expect(output).toBe(expected); 24 | }); 25 | 26 | test('verify test 3', () => { 27 | const expected = true; 28 | const boxes = [ 29 | { l: 1, w: 1, h: 1 }, 30 | { l: 2, w: 2, h: 2 } 31 | ]; 32 | const output = fitsInOneBox(boxes); 33 | 34 | expect(output).toBe(expected); 35 | }); 36 | 37 | test('verify test 4', () => { 38 | const expected = false; 39 | const boxes = [ 40 | { l: 1, w: 1, h: 1 }, 41 | { l: 2, w: 2, h: 2 }, 42 | { l: 3, w: 1, h: 3 } 43 | ]; 44 | const output = fitsInOneBox(boxes); 45 | 46 | expect(output).toBe(expected); 47 | }); 48 | 49 | test('verify test 5', () => { 50 | const expected = false; 51 | const boxes = [ 52 | { l: 1, w: 1, h: 1 }, 53 | { l: 2, w: 2, h: 2 }, 54 | { l: 2, w: 10, h: 2 } 55 | ]; 56 | const output = fitsInOneBox(boxes); 57 | 58 | expect(output).toBe(expected); 59 | }); 60 | 61 | test('verify test 6', () => { 62 | const expected = true; 63 | const boxes = [ 64 | { l: 1, w: 1, h: 1 }, 65 | { l: 3, w: 3, h: 3 }, 66 | { l: 2, w: 2, h: 2 } 67 | ]; 68 | const output = fitsInOneBox(boxes); 69 | 70 | expect(output).toBe(expected); 71 | }); 72 | -------------------------------------------------------------------------------- /src/challenge-05/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Para no cansar a los renos, Papá Noel quiere dejar el máximo número de regalos haciendo el menor número posible de viajes. 4 | 5 | Tiene un array de ciudades donde cada elemento es el número de regalos que puede dejar allí. `[12, 3, 11, 5, 7]`. Por otro lado, el límite de regalos que caben en su saco. Y, finalmente, el número de ciudades máximo que sus renos pueden visitar. 6 | 7 | Como no quiere dejar una ciudad a medias, **si no puede dejar todos los regalos que son de esa ciudad, no deja ninguno allí.** 8 | 9 | Crea un programa que le diga **la suma más alta de regalos** que podría repartir teniendo en cuenta el máximo de regalos que puede transportar y el número máximo de ciudades que puede visitar: 10 | 11 | ```js 12 | const giftsCities = [12, 3, 11, 5, 7]; 13 | const maxGifts = 20; 14 | const maxCities = 3; 15 | 16 | // la suma más alta de regalos a repartir 17 | // visitando un máximo de 3 ciudades 18 | // es de 20: [12, 3, 5] 19 | 20 | // la suma más alta sería [12, 7, 11] 21 | // pero excede el límite de 20 regalos y tendría 22 | // que dejar alguna ciudad a medias. 23 | 24 | getMaxGifts(giftsCities, maxGifts, maxCities); // 20 25 | ``` 26 | 27 | Si no se puede realizar ningún viaje que satisface los requerimientos, el resultado debe ser `0`. Más ejemplos: 28 | 29 | ```js 30 | getMaxGifts([12, 3, 11, 5, 7], 20, 3); // 20 31 | getMaxGifts([50], 15, 1); // 0 32 | getMaxGifts([50], 100, 1); // 50 33 | getMaxGifts([50, 70], 100, 1); // 70 34 | getMaxGifts([50, 70, 30], 100, 2); // 100 35 | getMaxGifts([50, 70, 30], 100, 3); // 100 36 | getMaxGifts([50, 70, 30], 100, 4); // 100 37 | ``` 38 | 39 | A tener en cuenta: 40 | 41 | - **maxGifts >= 1** 42 | - **giftsCities.length >= 1** 43 | - **maxCities >= 1** 44 | - **El número de maxCities puede ser mayor a giftsCities.length** 45 | -------------------------------------------------------------------------------- /src/challenge-05/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} giftsCities 3 | * @param {number} maxGifts 4 | * @param {number} maxCities 5 | */ 6 | export function getMaxGifts(giftsCities, maxGifts, maxCities) { 7 | return 0 8 | } 9 | -------------------------------------------------------------------------------- /src/challenge-05/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { getMaxGifts } from './solution.js'; 3 | 4 | test('it returns an number type', () => { 5 | const giftsCities = [12, 3, 11, 5, 7]; 6 | const maxGifts = 20; 7 | const maxCities = 3; 8 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 9 | 10 | expect(typeof output).toBe('number'); 11 | }); 12 | 13 | test('verify getMaxGifts([12, 3, 11, 5, 7], 20, 3)', () => { 14 | const expected = 20; 15 | const giftsCities = [12, 3, 11, 5, 7]; 16 | const maxGifts = 20; 17 | const maxCities = 3; 18 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 19 | 20 | expect(output).toBe(expected); 21 | }); 22 | 23 | test('verify getMaxGifts([50], 15, 1)', () => { 24 | const expected = 0; 25 | const giftsCities = [50]; 26 | const maxGifts = 15; 27 | const maxCities = 1; 28 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 29 | 30 | expect(output).toBe(expected); 31 | }); 32 | 33 | test('verify getMaxGifts([50], 100, 1)', () => { 34 | const expected = 50; 35 | const giftsCities = [50]; 36 | const maxGifts = 100; 37 | const maxCities = 1; 38 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 39 | 40 | expect(output).toBe(expected); 41 | }); 42 | 43 | test('verify getMaxGifts([50, 70, 30], 100, 2)', () => { 44 | const expected = 100; 45 | const giftsCities = [50, 70, 30]; 46 | const maxGifts = 100; 47 | const maxCities = 2; 48 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 49 | 50 | expect(output).toBe(expected); 51 | }); 52 | 53 | test('verify getMaxGifts([50, 70, 30], 100, 3)', () => { 54 | const expected = 100; 55 | const giftsCities = [50, 70, 30]; 56 | const maxGifts = 100; 57 | const maxCities = 3; 58 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 59 | 60 | expect(output).toBe(expected); 61 | }); 62 | 63 | test('verify getMaxGifts([50, 10, 40, 1000, 500, 200], 199, 4)', () => { 64 | const expected = 100; 65 | const giftsCities = [50, 10, 40, 1000, 500, 200]; 66 | const maxGifts = 199; 67 | const maxCities = 4; 68 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 69 | 70 | expect(output).toBe(expected); 71 | }); 72 | 73 | test('verify getMaxGifts([50, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 1000, 1000)', () => { 74 | const expected = 115; 75 | const giftsCities = [50, 10, 40, 1000, 500, 200]; 76 | const maxGifts = 1000; 77 | const maxCities = 1000; 78 | const output = getMaxGifts(giftsCities, maxGifts, maxCities); 79 | 80 | expect(output).toBe(expected); 81 | }); 82 | -------------------------------------------------------------------------------- /src/challenge-06/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Una pareja de entusiastas de la navidad ha creado una empresa de adornos navideños. El primer adorno que quieren fabricar es un cubo que se pone en los árboles. 4 | 5 | El problema es que tienen que programar la máquina y no saben cómo hacerlo. Nos han pedido ayuda para lograrlo. 6 | 7 | Para **crear los cubos** se le pasa un **número con el tamaño** deseado al programa y este devuelve un string con el **diseño de ese tamaño**. Por ejemplo, si le pasamos un 3, el programa debe devolver un cubo de 3x3x3: 8 | 9 | ```js 10 | const cube = createCube(3); 11 | ``` 12 | 13 | ``` 14 | /\_\_\_\ 15 | /\/\_\_\_\ 16 | /\/\/\_\_\_\ 17 | \/\/\/_/_/_/ 18 | \/\/_/_/_/ 19 | \/_/_/_/ 20 | ``` 21 | 22 | Como ves el cubo tiene tres caras visualmente. Los símbolos que se usan para construir las caras del cubo son: `/`, `\`, `_` y (espacio en blanco). 23 | 24 | Otros ejemplos de cubos: 25 | 26 | ```js 27 | const cubeOfOne = createCube(1); 28 | ``` 29 | 30 | ``` 31 | /\_\ 32 | \/_/ 33 | ``` 34 | 35 | ```js 36 | const cubeOfTwo = createCube(2); 37 | ``` 38 | 39 | ``` 40 | /\_\_\ 41 | /\/\_\_\ 42 | \/\/_/_/ 43 | \/_/_/ 44 | ``` 45 | 46 | A tener en cuenta: 47 | 48 | - **Fíjate bien en los espacios en blanco que hay en el cubo.** 49 | - **El cubo tiene que ser simétrico.** 50 | - **Asegúrate de usar los símbolos correctos.** 51 | - **Cada nueva línea del cubo debe terminar con un salto de línea (\n) excepto la última.** 52 | -------------------------------------------------------------------------------- /src/challenge-06/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} size 3 | */ 4 | export function createCube(size) { 5 | const space = ' '; 6 | const upperLeftPatter = '/\\'; 7 | const upperRightPattern = '_\\'; 8 | const lowerLeftPatter = '\\/'; 9 | const lowerRightPattern = '_/'; 10 | const topRightPart = upperRightPattern.repeat(size); 11 | const lowerRightPart = lowerRightPattern.repeat(size); 12 | const result = []; 13 | const numberOfRows = size * 2; 14 | 15 | const createCubeRow = (sizeRow, leftPatter, rightPart) => { 16 | const row = `${leftPatter.repeat(sizeRow)}${rightPart}`; 17 | const numberOfSpaces = size - sizeRow; 18 | const spaces = space.repeat(numberOfSpaces); 19 | 20 | return `${spaces}${row}`; 21 | }; 22 | 23 | for (let rowNumber = 1; rowNumber <= numberOfRows; rowNumber += 1) { 24 | const isTopPart = rowNumber <= size; 25 | const sizeRow = isTopPart ? rowNumber : numberOfRows - (rowNumber - 1); 26 | const row = isTopPart 27 | ? createCubeRow(sizeRow, upperLeftPatter, topRightPart) 28 | : createCubeRow(sizeRow, lowerLeftPatter, lowerRightPart); 29 | 30 | result.push(row); 31 | } 32 | 33 | return result.join('\n'); 34 | } 35 | -------------------------------------------------------------------------------- /src/challenge-06/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { createCube } from './solution.js'; 3 | 4 | test('it returns an string type', () => { 5 | const size = 1; 6 | const output = createCube(size); 7 | 8 | expect(typeof output).toBe('string'); 9 | }); 10 | 11 | test('verify createCube(3)', () => { 12 | const expected = ' /\\_\\_\\_\\\n /\\/\\_\\_\\_\\\n/\\/\\/\\_\\_\\_\\\n\\/\\/\\/_/_/_/\n \\/\\/_/_/_/\n \\/_/_/_/'; 13 | const size = 3; 14 | const output = createCube(size); 15 | 16 | expect(output).toBe(expected); 17 | }); 18 | 19 | test('verify createCube(1)', () => { 20 | const expected = '/\\_\\\n\\/_/'; 21 | const size = 1; 22 | const output = createCube(size); 23 | 24 | expect(output).toBe(expected); 25 | }); 26 | 27 | test('verify createCube(2)', () => { 28 | const expected = ' /\\_\\_\\\n/\\/\\_\\_\\\n\\/\\/_/_/\n \\/_/_/'; 29 | const size = 2; 30 | const output = createCube(size); 31 | 32 | expect(output).toBe(expected); 33 | }); 34 | 35 | test('verify createCube(10)', () => { 36 | const expected = 37 | ' /\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\/\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\/\\/\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n /\\/\\/\\/\\/\\/\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\_\\_\\_\\_\\_\\_\\_\\_\\_\\_\\\n\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/\\/\\/\\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/\\/\\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/\\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/\\/_/_/_/_/_/_/_/_/_/_/\n \\/_/_/_/_/_/_/_/_/_/_/'; 38 | const size = 10; 39 | const output = createCube(size); 40 | 41 | expect(output).toBe(expected); 42 | }); 43 | -------------------------------------------------------------------------------- /src/challenge-07/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-07/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} a1 3 | * @param {string[]} a2 4 | * @param {string[]} a3 5 | */ 6 | export function getGiftsToRefill(a1, a2, a3) { 7 | const gifts = [...new Set([...a1, ...a2, ...a3])]; 8 | const includeInStore = (gift, store) => Number(store.includes(gift)); 9 | const getNumberOfStores = (gift) => { 10 | return ( 11 | includeInStore(gift, a1) + 12 | includeInStore(gift, a2) + 13 | includeInStore(gift, a3) 14 | ); 15 | }; 16 | 17 | const isInOnlyStore = (gift) => getNumberOfStores(gift) === 1; 18 | 19 | const giftsToRefill = gifts.filter(isInOnlyStore); 20 | return giftsToRefill; 21 | } 22 | -------------------------------------------------------------------------------- /src/challenge-07/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { getGiftsToRefill } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-08/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-08/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} part 3 | */ 4 | export function checkPart(part) { 5 | return false 6 | } 7 | -------------------------------------------------------------------------------- /src/challenge-08/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { checkPart } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-09/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-09/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} leds 3 | */ 4 | export function countTime(leds) { 5 | let seconds = 0; 6 | 7 | let allOn = leds.every((n) => n === 1); 8 | const len = leds.length; 9 | 10 | while (!allOn) { 11 | leds = leds.map((n, index) => { 12 | let indexPrev = index === 0 ? len - 1 : index - 1; 13 | if (n === 0 && leds[indexPrev] === 1) { 14 | return 1; 15 | } 16 | 17 | return n; 18 | }); 19 | allOn = leds.every((n) => n === 1); 20 | seconds += 7; 21 | } 22 | 23 | return seconds; 24 | } 25 | -------------------------------------------------------------------------------- /src/challenge-09/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { countTime } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-10/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-10/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} heights 3 | */ 4 | export function checkJump(heights) { 5 | return false 6 | } -------------------------------------------------------------------------------- /src/challenge-10/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { checkJump } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-11/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-11/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} part 3 | * @param {string} total 4 | */ 5 | export function getCompleted(part, total) { 6 | return '1/1'; 7 | } 8 | -------------------------------------------------------------------------------- /src/challenge-11/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { getCompleted } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-12/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-12/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} distance 3 | * @param {Array<{ 4 | * name: string, 5 | * consumption: number 6 | * }>} sleighs 7 | */ 8 | export function selectSleigh(distance, sleighs) { 9 | return ''; 10 | } 11 | -------------------------------------------------------------------------------- /src/challenge-12/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { selectSleigh } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-13/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-13/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} lastBackup 3 | * @param {number[][]} changes 4 | */ 5 | export function getFilesToBackup(lastBackup, changes) { 6 | return [] 7 | } 8 | -------------------------------------------------------------------------------- /src/challenge-13/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { getFilesToBackup } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-14/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-14/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[][]} path 3 | */ 4 | export function getOptimalPath(path) { 5 | return 0 6 | } 7 | -------------------------------------------------------------------------------- /src/challenge-14/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { getOptimalPath } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-15/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-15/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} base 3 | */ 4 | export function decorateTree(base) { 5 | return [] 6 | } 7 | -------------------------------------------------------------------------------- /src/challenge-15/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { decorateTree } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-16/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-16/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} letter 3 | */ 4 | export function fixLetter(letter) { 5 | return letter; 6 | } 7 | -------------------------------------------------------------------------------- /src/challenge-16/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { fixLetter } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-17/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-17/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} gifts 3 | * @param {number} maxWeight 4 | */ 5 | export function carryGifts(gifts, maxWeight) { 6 | return []; 7 | } 8 | -------------------------------------------------------------------------------- /src/challenge-17/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { carryGifts } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-18/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-18/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number} dry 3 | * @param {number} numbers 4 | */ 5 | export function dryNumber(dry, numbers) { 6 | return [] 7 | } 8 | -------------------------------------------------------------------------------- /src/challenge-18/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { dryNumber } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-19/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-19/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} toys 3 | * @param {number[]} positions 4 | */ 5 | export function sortToys(toys, positions) { 6 | return [] 7 | } 8 | -------------------------------------------------------------------------------- /src/challenge-19/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { sortToys } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-20/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-20/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Array<{ 3 | * type: string, 4 | * weightCapacity: number 5 | * }>} reindeerTypes 6 | * @param {Array<{ 7 | * country: string, 8 | * weight: number 9 | * }>} gifts 10 | */ 11 | export function howManyReindeers(reindeerTypes, gifts) { 12 | return []; 13 | } 14 | -------------------------------------------------------------------------------- /src/challenge-20/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { howManyReindeers } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-21/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | Hay muchas cartas de niños pidiendo regalos y es muy difícil que podamos hacer inventario de todos ellos. Por eso, hemos decidido crear un programa que nos dibuje una tabla con los regalos que nos piden y sus cantidades. 4 | 5 | Para ello nos dan un array de objetos con los nombres de los regalos y sus cantidades. Escribe una función que reciba este array y devuelva una cadena con la tabla dibujada. 6 | 7 | ```js 8 | printTable([ 9 | { name: 'Game', quantity: 2 }, 10 | { name: 'Bike', quantity: 1 }, 11 | { name: 'Book', quantity: 3 } 12 | ]); 13 | ``` 14 | 15 | ``` 16 | +++++++++++++++++++ 17 | | Gift | Quantity | 18 | | ---- | -------- | 19 | | Game | 2 | 20 | | Bike | 1 | 21 | | Book | 3 | 22 | ******************* 23 | ``` 24 | 25 | Otro ejemplo donde se puede ver que la tabla siempre usa sólo el espacio justo dependiendo de la longitud de los nombres de los regalos y de las cantidades. 26 | 27 | ```js 28 | printTable([ 29 | { name: 'PlayStation 5', quantity: 9234782374892 }, 30 | { name: 'Book Learn Web Dev', quantity: 23531 } 31 | ]); 32 | ``` 33 | 34 | ``` 35 | ++++++++++++++++++++++++++++++++++++++ 36 | | Gift | Quantity | 37 | | ------------------ | ------------- | 38 | | PlayStation 5 | 9234782374892 | 39 | | Book Learn Web Dev | 23531 | 40 | ************************************** 41 | ``` 42 | 43 | Como ves, el tamaño de las celdas depende de la longitud de los nombres de los regalos y de las cantidades, aunque como mínimo tendrán que ser del espacio de los títulos Gift y Quantity respectivamente. 44 | 45 | La tabla usa los símbolos: + para el borde superior, \* para el borde inferior, - para las líneas horizontales y | para las líneas verticales. 46 | 47 | Ten en cuenta: 48 | 49 | Usa sólo el espacio que necesitas para dibujar la tabla. 50 | Adapta la tabla a la longitud de los nombres de los regalos y de las cantidades o los títulos de las columnas. 51 | No hace falta que ordenes los resultados. 52 | La tabla no termina con salto de línea. 53 | -------------------------------------------------------------------------------- /src/challenge-21/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {Array<{ 3 | * name: string, 4 | * quantity: number 5 | * }>} gifts 6 | */ 7 | export function printTable(gifts) { 8 | return ''; 9 | } 10 | -------------------------------------------------------------------------------- /src/challenge-21/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { printTable } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-22/README.md: -------------------------------------------------------------------------------- 1 | # Instrucciones 2 | 3 | ```js 4 | ``` -------------------------------------------------------------------------------- /src/challenge-22/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} systemNames 3 | * @param {number[]} stepNumbers 4 | */ 5 | export function checkStepNumbers(systemNames, stepNumbers) { 6 | return true 7 | } 8 | -------------------------------------------------------------------------------- /src/challenge-22/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { checkStepNumbers } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-23/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neftdev/adventjs-retos/624bcc0db279566355e1f3e4387335685d8f1a21/src/challenge-23/README.md -------------------------------------------------------------------------------- /src/challenge-23/solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string[]} commands 3 | */ 4 | export function executeCommands(commands) { 5 | return [] 6 | } 7 | -------------------------------------------------------------------------------- /src/challenge-23/solution.test.js: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | import { executeCommands } from './solution.js'; 3 | 4 | test('it returns an type', () => { 5 | }); 6 | 7 | test("verify", () => { 8 | }); 9 | -------------------------------------------------------------------------------- /src/challenge-24/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neftdev/adventjs-retos/624bcc0db279566355e1f3e4387335685d8f1a21/src/challenge-24/README.md -------------------------------------------------------------------------------- /src/challenge-24/solution.js: -------------------------------------------------------------------------------- 1 | //@ts-check 2 | /** 3 | * @param {string[][]} maze 4 | */ 5 | function canExit(maze) { 6 | const START = 'S'; 7 | const EXIT = 'E'; 8 | const SPACE = ' '; 9 | const VISITED = 'V'; 10 | const moveBases = [ 11 | [-1, 0], 12 | [0, -1], 13 | [0, 1], 14 | [1, 0] 15 | ]; 16 | 17 | const startRowIndex = maze.findIndex( 18 | (row) => row.findIndex((cell) => cell === START) !== -1 19 | ); 20 | const startColumnIndex = maze[startRowIndex].findIndex( 21 | (cell) => cell === START 22 | ); 23 | 24 | maze[startRowIndex][startColumnIndex] = SPACE; 25 | 26 | /** 27 | * @param {number} rowIndex 28 | * @param {number} columnIndex 29 | */ 30 | const getNextIndices = (rowIndex, columnIndex) => { 31 | const moves = 32 | moveBases.find(([x, y]) => { 33 | const nextRowIndex = rowIndex + x; 34 | const nextColumnIndex = columnIndex + y; 35 | const foundCell = checkIfThereIsExit(nextRowIndex, nextColumnIndex); 36 | return foundCell; 37 | }) || []; 38 | 39 | return moves; 40 | }; 41 | 42 | /** 43 | * @param {number} rowIndex 44 | * @param {number} columnIndex 45 | * @returns {boolean} 46 | */ 47 | const existNextIndices = (rowIndex, columnIndex) => { 48 | maze[rowIndex][columnIndex] = VISITED; 49 | 50 | const [x, y] = getNextIndices(rowIndex, columnIndex); 51 | const indicesExist = x !== undefined && y !== undefined; 52 | 53 | return indicesExist; 54 | }; 55 | 56 | /** 57 | * @param {number} rowIndex 58 | * @param {number} columnIndex 59 | * @returns {boolean} 60 | */ 61 | const checkIfThereIsExit = (rowIndex, columnIndex) => { 62 | const row = maze[rowIndex] || []; 63 | const cell = row[columnIndex]; 64 | const thereIsExit = 65 | cell !== undefined && 66 | (cell === EXIT || 67 | (cell === SPACE && existNextIndices(rowIndex, columnIndex))); 68 | 69 | return thereIsExit; 70 | }; 71 | 72 | const exitWasFound = checkIfThereIsExit(startRowIndex, startColumnIndex); 73 | 74 | return exitWasFound; 75 | } 76 | -------------------------------------------------------------------------------- /src/challenge-24/solution.test.js: -------------------------------------------------------------------------------- 1 | // import { expect, test } from 'vitest'; 2 | // import { } from './solution.js'; 3 | 4 | // test('it returns an type', () => { 5 | // }); 6 | 7 | // test("verify", () => { 8 | // }); 9 | -------------------------------------------------------------------------------- /src/challenge-25/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neftdev/adventjs-retos/624bcc0db279566355e1f3e4387335685d8f1a21/src/challenge-25/README.md -------------------------------------------------------------------------------- /src/challenge-25/solution.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neftdev/adventjs-retos/624bcc0db279566355e1f3e4387335685d8f1a21/src/challenge-25/solution.js -------------------------------------------------------------------------------- /src/challenge-25/solution.test.js: -------------------------------------------------------------------------------- 1 | // import { expect, test } from 'vitest'; 2 | // import { } from './solution.js'; 3 | 4 | // test('it returns an type', () => { 5 | // }); 6 | 7 | // test("verify", () => { 8 | // }); 9 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | /// 2 | import { defineConfig } from 'vite'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | test: {} 7 | }); 8 | --------------------------------------------------------------------------------