Skip to content

2024 01 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 1, 2024
Merged
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
20 changes: 20 additions & 0 deletions 2024/01-primer-regalo-repetido/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Reto 01: 🎁 ¡Primer regalo repetido!

**Santa Claus** 🎅 ha recibido una lista de números mágicos que representan regalos 🎁, pero algunos de ellos están duplicados y deben ser eliminados para evitar confusiones. Además, **los regalos deben ser ordenados en orden ascendente antes de entregárselos a los elfos.**

Tu tarea es escribir una función que reciba una lista de números enteros (que pueden incluir duplicados) y devuelva una nueva lista sin duplicados, ordenada en orden ascendente.

```js
const gifts1 = [3, 1, 2, 3, 4, 2, 5]
const preparedGifts1 = prepareGifts(gifts1)
console.log(preparedGifts1) // [1, 2, 3, 4, 5]

const gifts2 = [6, 5, 5, 5, 5]
const preparedGifts2 = prepareGifts(gifts2)
console.log(preparedGifts2) // [5, 6]

const gifts3 = []
const preparedGifts3 = prepareGifts(gifts3)
console.log(preparedGifts3) // []
// No hay regalos, la lista queda vacía
```
5 changes: 5 additions & 0 deletions 2024/01-primer-regalo-repetido/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function prepareGifts(gifts) {
return [...new Set(gifts)].sort((a, b) => a - b);
}

module.exports = prepareGifts;
39 changes: 39 additions & 0 deletions 2024/01-primer-regalo-repetido/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const prepareGifts = require('./index');

describe('01 => Primer-regalo-repetido', () => {
const TEST_CASES = [
{
input: [3, 1, 2, 3, 4, 2, 5],
output: [1, 2, 3, 4, 5],
},
{
input: [5, 5, 5, 5],
output: [5],
},
{
input: [1, 2, 3],
output: [1, 2, 3],
},
{
input: [],
output: [],
},
{
input: [10, 20, 10, 30, 20, 30, 40],
output: [10, 20, 30, 40],
},
{
input: [3, 1, 2, 3, 1, 2],
output: [1, 2, 3],
},
];

it('should return an array', () => {
const { input } = TEST_CASES[0];
expect(prepareGifts(input)).toBeInstanceOf(Array);
});

it.each(TEST_CASES)('should return $output', ({ input, output }) => {
expect(prepareGifts(input)).toEqual(output);
});
});
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img
alt="adventjs-2023"
src="https://res.cloudinary.com/dfeujtobk/image/upload/v1701756989/Challenges/u0qn1htendtskutrml9j.png"
alt="adventjs-2024"
src="https://res.cloudinary.com/dfeujtobk/image/upload/v1733035253/advent-js/Apex_1733035172447_syuzaa.png"
width="1200"
style="border-radius: 1rem" />
<br />
Expand Down Expand Up @@ -44,17 +44,33 @@ npm run test:2021
npm run test:2022
# or
npm run test:2023
# or
npm run test:2024

# Run specific test
npm run test 'year'/'challenge'/index.test.js

```

## 🎯 2023 Challenges
## 🎯 2024 Challenges

<details open>
<summary>Show / Hide</summary>

| # | Challenge | Difficulty | My Solution | My Score |
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :------------------------------------------------------------------------------------------------------------: | :-----------: |
| 01 | [🎁 ¡Primer regalo repetido!](https://adventjs.dev/es/challenges/2024/1) | 🟢 | [here](./2024/01-primer-regalo-repetido/index.js) | ⭐⭐⭐⭐⭐ |

Difficulties legend:
🟢 Easy 🟡 Medium 🔴 Hard

</details>

## 🎯 2023 Challenges

<details hide>
<summary>Show / Hide</summary>

| # | Challenge | Difficulty | My Solution |
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :------------------------------------------------------------------------------------------------------------: |
| 01 | [¡Primer regalo repetido!](https://adventjs.dev/es/challenges/2023/1) | 🟢 | [here](https://github.com/marcode24/adventjs-solutions/tree/main/2023/01-primer-regalo-repetido) |
Expand Down
31 changes: 17 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
"test:2021": "jest --testPathPattern=2021",
"test:2022": "jest --testPathPattern=2022",
"test:2023": "jest --testPathPattern=2023",
"test:2024": "jest --testPathPattern=2024",
"lint": "eslint **/*.js",
"lint:fix": "eslint **/*.js --fix",
"prepare": "husky install"
"prepare": "husky install",
"postinstall": "npm run prepare"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all"
},
"keywords": [
"midudev",
Expand Down