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)}`); |
That's the trick :)
…On Thu, Oct 26, 2023, 09:56 Markus Hammelmann ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks, I should have read more carefully.....not just flying over the
sample, not even realizing there were spaces....
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/dk5ax/ca1d80b011a029f361cba3667682d9e8#gistcomment-4739298>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADJRFXFRCMHSN5GFFWZYTYBIJUJBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTENJYGIZTSMRYU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Ok, should be fine now....is there some broader data set available to test with?
Not yet :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, I should have read more carefully.....not just flying over the sample, not even realizing there were spaces....