Advent Of Vue is a series of 24 Vue coding challenges that are sent out every day from December 1 to December 24 via a dedicated newsletter. If you'd like to receive more of these puzzles in the future, go ahead and sign up!
The elves decided that in the spirit of leveling up the Christmas Spirit, they want to promote "Secret Santa".
The principle of Secret Santa is rather simple: Everyone gives a gift to exactly ONE other person. This means that everyone receives exactly ONE present, no matter how many people participate. The mechanism should be random.
To promote this, the elves want to provide a web application that automatically matches every participating person randomly.
The code is almost finished, but the developer elves got stuck on the most difficult part: Actually assigning random "secret santas" to everyone.
This is where you some in!
In the file src/helpers/match.js
, there is a function matchPeople
to be completed.
The input is an array of names and emails:
[
{ name: 'Kevin McCallister', email: '[email protected]' },
{ name: 'John McClane', email: '[email protected]' },
...
]
The goal is it to return an array that assigns every name (receiver of gift) a secret santa (giver of gift). The array should have the following structure: [ { receiver: { name: 'Kevin McCallister', email: '[email protected]' }, giver: { name: 'John McClane', email: '[email protected]' } }, ... ]
There are two rules to be followed:
- For every person there has to be one (and only one) giver
- A person cannot be their own giver
https://majestic-douhua-02c095.netlify.app/
Marc Backes:
Based on a Stackblitz project by tony19