diff --git a/solutions/javascript/elyses-destructured-enchantments/1/enchantments.js b/solutions/javascript/elyses-destructured-enchantments/1/enchantments.js new file mode 100644 index 0000000..eef78ad --- /dev/null +++ b/solutions/javascript/elyses-destructured-enchantments/1/enchantments.js @@ -0,0 +1,81 @@ +/// +// @ts-check + +/** + * Get the first card in the given deck + * + * @param {Card[]} deck + * + * @returns {Card} the first card in the deck + */ +export function getFirstCard(deck) { + const [first] = deck; + return first; +} + +/** + * Get the second card in the given deck + * + * @param {Card[]} deck + * + * @returns {Card} the second card in the deck + */ +export function getSecondCard(deck) { + const [,second] = deck; + return second; +} + +/** + * Switch the position of the two cards + * + * @param {[Card, Card]} deck + * + * @returns {[Card, Card]} new deck with the 2 cards swapped + */ +export function swapTwoCards(deck) { + const [first,second,...rest] = deck; + return [second, first,...rest]; + +} + +/** + * Rotate (shift) the position of the three cards (by one place) + * + * @param {[Card, Card, Card]} deck + * + * @returns {[Card, Card, Card]} new deck with the 3 cards shifted by one position + */ +export function shiftThreeCardsAround(deck) { + const [first,second,third,...rest] = deck; + return [second,third,first,... rest]; +} + +/** + * Grab the chosen pile from the available piles + * + * @param {{ chosen: Card[], disregarded: Card[] }} piles + * + * @returns {Card[]} the pile named chosen + */ +export function pickNamedPile({chosen }) { + // 🚨 Do NOT use piles.chosen or piles.disregarded. + + + return chosen; + +} + +/** + * Swap the chosen pile for the disregarded pile and the disregarded pile for the chosen pile + * + * @param {{ chosen: Card[], disregarded: Card[] }} piles + * @returns {{ chosen: Card[], disregarded: Card[] }} new piles where the two piles are swapped + */ +export function swapNamedPile({ chosen, disregarded }) { + // 🪄 Don't break the magic. + // 🚨 Do NOT use piles.chosen or piles.disregarded. + // 🚨 Do NOT touch the next line or Elyse will accidentally reveal the trick. + + + return { chosen: disregarded, disregarded: chosen }; +}