Live data from Hacker News

Show HN: A TO-DO app that fits inside a single tweet

ruky.me

21–30 of 56 posts

Re: Show HN: A TO-DO app that fits inside a single tweet

#21
post #12

Earlier quoted context omitted.

Care to elaborate? There are some nifty tricks when it comes to golfing JS.

Well sorry I was in a hurry when I typed the above comment Well the body can’t have any dom elements according to the challenger That means I had to create the dom elements as well and I was unable to figure out a way within the given character limit

I wonder if document.write() would work for you. The old-fashioned APIs from before the DOM era (e.g innerHTML, innerText) generally seem to be a lot shorter although they're still a bit verbose.

Re: Show HN: A TO-DO app that fits inside a single tweet

#22
post #3
post #2

I am not very familiar with JS but doesn't loading a framework externally kind of defeat the purpose?

Op here: you can’t do it with plain js Plus it’s ok to use frameworks according to the tweet

I don't mean to make this into a code golf thread, but saying it "can't" be done in plain JS was too enticing not to try it. Does this meet the requirements?

let win=window;document.body.innerHTML=``,win.b.onclick=a=>{let b=win.c.appendChild(document.createElement("p"));b.innerText=win.a.value,win.a.value="",b.onclick=()=>win.c.removeChild(b)};

JS Fiddle: https://jsfiddle.net/2z0bus8d/

While I think there's always the standard caveat around code golf in JS (you're building on a vast set of APIs and an often resource hungry platform), reaching for a framework really doesn't feel in the spirit of this kind of puzzle.

Re: Show HN: A TO-DO app that fits inside a single tweet

#23
Here is my attempt! Please note that in the original tweet the "code" including the 3rd party library seems to be excluded so I also excluded it:

https://jsfiddle.net/franciscop/gexfdq1y/

https://twitter.com/FPresencia/status/1340952793352310785

Notably, and differently from the solution of the person originally issuing the challenge and from this HN entry of Rukshan answering to the challenge, I solved it including the three constrains:

• Esc to clear the list

• Enter to add item

• Click an item to cross/uncross it

Here is a cleaned-up and explained version of the same:

https://jsfiddle.net/franciscop/x1sc7rk9/

Re: Show HN: A TO-DO app that fits inside a single tweet

#24
This is an interesting problem in the same way that many other codegolf problems are interesting. The question isn’t about solving something that’s directly applicable to everyday life, but instead it’s exploring what is possible in the language/framework provided as guidelines for the competition. So as long as we take it at face value it’s a fun and entertaining thought exercise.

Re: Show HN: A TO-DO app that fits inside a single tweet

#25
post #22
post #3

Earlier quoted context omitted.

Op here: you can’t do it with plain js Plus it’s ok to use frameworks according to the tweet

I don't mean to make this into a code golf thread, but saying it "can't" be done in plain JS was too enticing not to try it. Does this meet the requirements? let win=window;document.body.innerHTML=` `,win.b.onclick=a=>{let b=win.c.appendChild(document.createElement("p"));b.innerText=win.a.value,win.a.value="",b.onclick=()=>win.c.removeChild(b)}; JS Fiddle: https://jsfiddle.net/2z0bus8d/ While I think there's always t…

This has to be the best solution I have seen, I feel it ticks all boxes and better yet it doesn’t use any external libraries like I did

I found it difficult manipulate DOM with just js without hitting the limit, well done sir, you deserve a cookie

Re: Show HN: A TO-DO app that fits inside a single tweet

#26
Funny thing, if you make the most straightforward no dependency version in "Vanilla HTML+CSS+JS" you'll easily get below 250 characters, but it will break the last rule

> Starting HTML body should be empty except the

Because you'll have no tag. To fulfill this, you'll have to unnecessarily wrap the whole thing in script, like:

    document.write(`:checked+*{text-decoration:line-through}#t{display:none}

+×`)

(277 chars, golfable even further, but I'm not going to replace button elements with something inappropriate.)

Re: Show HN: A TO-DO app that fits inside a single tweet

#27
post #21
post #12

Earlier quoted context omitted.

Well sorry I was in a hurry when I typed the above comment Well the body can’t have any dom elements according to the challenger That means I had to create the dom elements as well and I was unable to figure out a way within the given character limit

I wonder if document.write() would work for you. The old-fashioned APIs from before the DOM era (e.g innerHTML, innerText) generally seem to be a lot shorter although they're still a bit verbose.

Yes I guess that was the right way all along, I saw a comment on this thread using innerHtml and write

Re: Show HN: A TO-DO app that fits inside a single tweet

#30
post #28

I think it should have been an absolute no-brainer to avoid external libraries. I'm rather disappointed in the challenge tweet for even allowing that.

Yes it would have been more interesting and made me think harder without using a shortcut with a framework
Post reply on HN