Skip to content

Instantly share code, notes, and snippets.

@mariobot
Created December 5, 2024 22:57
Show Gist options
  • Select an option

  • Save mariobot/986ca659f8b0363099c40599ddff347a to your computer and use it in GitHub Desktop.

Select an option

Save mariobot/986ca659f8b0363099c40599ddff347a to your computer and use it in GitHub Desktop.
adventjs.dev @mariobot
// Day 1
/**
* @param {number[]} gifts - The array of gifts to prepare
* @returns {number[]} An array with the prepared gifts
*/
function prepareGifts(gifts) {
let list = [];
for(var i = 0; i < gifts.length; i++)
{
if(!list.includes(gifts[i]))
{
if (Number.isInteger(gifts[i])) {
list.push(gifts[i]);
}
}
}
return list.sort((a, b) => a - b);
}
// Day 2
/**
* @param {string[]} names - Array of names to frame
* @returns {string} The framed names
*/
function createFrame(names) {
var maxL = 0;
for(var i = 0; i < names.length; i++)
{
if(names[i].length >= maxL)
maxL = names[i].length
}
var response;
response = '*'.repeat(maxL)+'****\n';
for(var i = 0; i < names.length; i++)
{
var complete = maxL - names[i].length;
response +='* '+names[i]+' '.repeat(complete)+' *\n';
}
response +='*'.repeat(maxL)+'****';
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment