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
Show HN: A TO-DO app that fits inside a single tweet
21–30 of 56 posts
Re: Show HN: A TO-DO app that fits inside a single tweet
#22I 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
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
#23https://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:
Re: Show HN: A TO-DO app that fits inside a single tweet
#24Re: Show HN: A TO-DO app that fits inside a single tweet
#25Earlier 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…
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> 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
#27Earlier 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.
Re: Show HN: A TO-DO app that fits inside a single tweet
#28Re: Show HN: A TO-DO app that fits inside a single tweet
#29Using Vue.js for this task is like pouring a jug of milk with a crane.
Re: Show HN: A TO-DO app that fits inside a single tweet
#30I 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.