Skip to content

Commit c8fa9ef

Browse files
authored
Merge pull request #19 from marcode24/2024-01
2024 01
2 parents f283cbf + 3874f7b commit c8fa9ef

File tree

6 files changed

+107
-18
lines changed

6 files changed

+107
-18
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Reto 01: 🎁 ¡Primer regalo repetido!
2+
3+
**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.**
4+
5+
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.
6+
7+
```js
8+
const gifts1 = [3, 1, 2, 3, 4, 2, 5]
9+
const preparedGifts1 = prepareGifts(gifts1)
10+
console.log(preparedGifts1) // [1, 2, 3, 4, 5]
11+
12+
const gifts2 = [6, 5, 5, 5, 5]
13+
const preparedGifts2 = prepareGifts(gifts2)
14+
console.log(preparedGifts2) // [5, 6]
15+
16+
const gifts3 = []
17+
const preparedGifts3 = prepareGifts(gifts3)
18+
console.log(preparedGifts3) // []
19+
// No hay regalos, la lista queda vacía
20+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function prepareGifts(gifts) {
2+
return [...new Set(gifts)].sort((a, b) => a - b);
3+
}
4+
5+
module.exports = prepareGifts;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const prepareGifts = require('./index');
2+
3+
describe('01 => Primer-regalo-repetido', () => {
4+
const TEST_CASES = [
5+
{
6+
input: [3, 1, 2, 3, 4, 2, 5],
7+
output: [1, 2, 3, 4, 5],
8+
},
9+
{
10+
input: [5, 5, 5, 5],
11+
output: [5],
12+
},
13+
{
14+
input: [1, 2, 3],
15+
output: [1, 2, 3],
16+
},
17+
{
18+
input: [],
19+
output: [],
20+
},
21+
{
22+
input: [10, 20, 10, 30, 20, 30, 40],
23+
output: [10, 20, 30, 40],
24+
},
25+
{
26+
input: [3, 1, 2, 3, 1, 2],
27+
output: [1, 2, 3],
28+
},
29+
];
30+
31+
it('should return an array', () => {
32+
const { input } = TEST_CASES[0];
33+
expect(prepareGifts(input)).toBeInstanceOf(Array);
34+
});
35+
36+
it.each(TEST_CASES)('should return $output', ({ input, output }) => {
37+
expect(prepareGifts(input)).toEqual(output);
38+
});
39+
});

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div align="center">
22
<img
3-
alt="adventjs-2023"
4-
src="https://res.cloudinary.com/dfeujtobk/image/upload/v1701756989/Challenges/u0qn1htendtskutrml9j.png"
3+
alt="adventjs-2024"
4+
src="https://res.cloudinary.com/dfeujtobk/image/upload/v1733035253/advent-js/Apex_1733035172447_syuzaa.png"
55
width="1200"
66
style="border-radius: 1rem" />
77
<br />
@@ -44,17 +44,33 @@ npm run test:2021
4444
npm run test:2022
4545
# or
4646
npm run test:2023
47+
# or
48+
npm run test:2024
4749

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

5153
```
5254

53-
## 🎯 2023 Challenges
55+
## 🎯 2024 Challenges
5456

5557
<details open>
5658
<summary>Show / Hide</summary>
5759

60+
| # | Challenge | Difficulty | My Solution | My Score |
61+
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :------------------------------------------------------------------------------------------------------------: | :-----------: |
62+
| 01 | [🎁 ¡Primer regalo repetido!](https://adventjs.dev/es/challenges/2024/1) | 🟢 | [here](./2024/01-primer-regalo-repetido/index.js) | ⭐⭐⭐⭐⭐ |
63+
64+
Difficulties legend:
65+
🟢 Easy 🟡 Medium 🔴 Hard
66+
67+
</details>
68+
69+
## 🎯 2023 Challenges
70+
71+
<details hide>
72+
<summary>Show / Hide</summary>
73+
5874
| # | Challenge | Difficulty | My Solution |
5975
| :-: | ------------------------------------------------------------------------------------------- | :--------: | :------------------------------------------------------------------------------------------------------------: |
6076
| 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) |

package-lock.json

Lines changed: 17 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
"test:2021": "jest --testPathPattern=2021",
99
"test:2022": "jest --testPathPattern=2022",
1010
"test:2023": "jest --testPathPattern=2023",
11+
"test:2024": "jest --testPathPattern=2024",
1112
"lint": "eslint **/*.js",
1213
"lint:fix": "eslint **/*.js --fix",
13-
"prepare": "husky install"
14+
"prepare": "husky install",
15+
"postinstall": "npm run prepare"
16+
},
17+
"prettier": {
18+
"singleQuote": true,
19+
"trailingComma": "all"
1420
},
1521
"keywords": [
1622
"midudev",

0 commit comments

Comments
 (0)