Last active
October 26, 2023 09:32
-
-
Save dk5ax/ca1d80b011a029f361cba3667682d9e8 to your computer and use it in GitHub Desktop.
Initial thoughts on https://gist.github.com/codepo8/84248aea816544c8e730c8dffb975c0e#puzzle-event-block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const input = { | |
"columns": 80, | |
"padChar": "·", | |
"events": [ | |
{ "name": "Code 100", "location": "Zagreb, Croatia", "date": "29.11.2023" }, | |
{ "name": "LIVE", "date": "ongoing" }, | |
{ "name": "Coffee With Developers", "location": "various", "date": "ongoing"} , | |
{ "name": "World Congress","location": "Berlin, Germany", "date":"17-19.07.2024" } | |
] | |
}; | |
console.log(`${input.padChar.repeat(input.columns)}`); | |
input.events.forEach(event => { | |
const name = ((event.name?.length) ?? 0) ? (' ' + event.name + ' ') : ''; | |
const location = ((event.location?.length) ?? 0) ? (' ' + event.location + ' ') : ''; | |
const date = ((event.date?.length) ?? 0) ? (' ' + event.date + ' ') : ''; | |
const toPadCount = input.columns - 2 - (name.length) - (location.length) - (date.length) | |
const lspaces = Math.floor(input.columns/2-(name.length)) - Math.floor(location.length / 2); | |
const rspaces = toPadCount - lspaces; | |
console.log(`${input.padChar}${name}${input.padChar.repeat(lspaces)}${location}${input.padChar.repeat(rspaces)}${date}${input.padChar}`); | |
}); | |
console.log(`${input.padChar.repeat(input.columns)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, should be fine now....is there some broader data set available to test with?