Skip to content

Commit d920326

Browse files
committed
✨ Add challenge-01 solution
1 parent e25db5b commit d920326

File tree

3 files changed

+64
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)