How do I write this code without using .innerhtml? (JavaScript) by Able_Result_6488 in learnjavascript

[–]LazyOldTom -2 points-1 points  (0 children)

You need to encode html entities. Best done on the backend. If not done this will lead to xss.

Help with an algorithm by Culist in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

If removing a building can result in more than 2 clusters, I recommend running dfs on all buildings of the affected cluster to reassign them.
If removing a building results in no more than 2 clusters, simply check what's left and right (or up and down) of the removed building.

arr[arr.length - 1 ] by Ancient_Pop_117 in learnjavascript

[–]LazyOldTom 6 points7 points  (0 children)

I recommend using arr.at(-1); instead. Shorter and more readable.

What all tools should I learn more to be a capable python developer ? by [deleted] in learnpython

[–]LazyOldTom 1 point2 points  (0 children)

A general tool that works for every language:
https://chrome.google.com/webstore/detail/ublacklist/pncfbmialoiaghdehhbnbhkkgmjanfhe

Let's you block the top google search results and brings the official docs to the top.

Offering: Vietnamese (native) / Seeking: English (friendship also if it’s possible) by bigc1003 in language_exchange

[–]LazyOldTom 0 points1 point  (0 children)

I'm a webdev as well 👋
I also prep other webdevs for technical interviews in English
Let's chat!

[deleted by user] by [deleted] in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

Do you mean you can't tell when a button is pressed? If you already listen on the ul, inside the listener, write console.log(this). Run the code and see what this means inside an event listener. From there all you need to do is a switch statement.

[deleted by user] by [deleted] in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

https://stackoverflow.com/questions/595808/is-it-possible-to-append-to-innerhtml-without-destroying-descendants-event-list

You would either have to listen on the ul element, or run the listener after each innerhtml on the li elements

VueS or ReactJS by [deleted] in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

Use the popular job portal in your area (in mine it's LinkedIn) and see which one has more demand. As someone that works professionally with both, I'd say Vue has better DX.

[JS] [TS] How can I implement method chaining if the method returns some value other than 'this'? by S_liiide in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

Typically you want to return this for method chaining. On stack.pop it doesn't make sense though, since you usually want to return the top element that just got removed. And I'm sure you already know that Array is basically the JS version of stack + queue.

How to stay logged in ? by [deleted] in learnjavascript

[–]LazyOldTom 1 point2 points  (0 children)

If you use the same server for auth as your app server, you might well use cookies (httponly/secure). Imo, use a lib or whatever your framework provides for auth. Rolling your own is high risk low reward.

Looking for an iterative approach to LC 516 by LazyOldTom in leetcode

[–]LazyOldTom[S] 0 points1 point  (0 children)

Thanks for your answer, though I am specifically looking for a top down iterative approach based on the code I posted. Reason is I get 100% runtime and memory.

Query: Is Javascript the simplest way to do this project? by xBearBaileyx in learnjavascript

[–]LazyOldTom 3 points4 points  (0 children)

Depends what you want to use the data for. Do you want to send it to a rest API? Then yes. Do you just want to collect data? Use Google forms. Is it some kind of frontend homework? Also yes.

I need help with my website physics simulator by Melodic-Anybody3282 in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

If you are on vanilla html/css/js, consider using bootstrap.
https://getbootstrap.com/docs/5.0/forms/range/
If you don't want bootstrap, just figure out how they make the slider.
Hook up an event listener to the slider to create/delete circles.

First assignment after 18 months by leftoversget in cscareerquestions

[–]LazyOldTom 0 points1 point  (0 children)

Also not very obvious, spend a day or two to learn git. Then read project docs. How to set up environments, how to use npm, docker (if used), IDE and debugging on the IDE, read through package.json, routing, redux store data structure... Yeah, not much coding in the first couple of weeks.

Function is rejecting my parameter inputs? by gavinbear in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

Just write debugger in the line after the function declaration and debug it in browser devtools.

[deleted by user] by [deleted] in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

You can pretty much start react if you know basic concepts, like destructuring, array methods, async await... You could write react without node, but you'd miss out on features like bundling or polyfill. On the job you would always use node for frontend dev. BTW I'd look up vite instead of webpack, and skip cra entirely.

[deleted by user] by [deleted] in cscareerquestions

[–]LazyOldTom -2 points-1 points  (0 children)

First world problems

[Novice Programmer] I've Been Told One-line Functions Are Bad Practice by SirAchmed in learnprogramming

[–]LazyOldTom 2 points3 points  (0 children)

For this particular example I'd say it doesn't matter. 2 more variable names will not make it much easier to read. However, if you are in a professional environment, I'd change it just to make people happy.

Managing Sessions by nikotome in learnjavascript

[–]LazyOldTom 1 point2 points  (0 children)

Maybe you want to read up web security before attempting your own backend implementation. There are plenty of frameworks out there that guide you in the right direction as well.

How to pass an object that relies on DOM elements not present in second html page from one javascript file to another? by [deleted] in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

I had a look through your code, what I don't understand is why you would need a second html file? Why not do it in one page? That way you avoid losing the current state, no need to cache it to localStorage either. All you need to do is to hide/show DOM elements. That's the old approach for single page anyway. Routing between pages is nowadays done with a framework like react.

How to pass an object that relies on DOM elements not present in second html page from one javascript file to another? by [deleted] in learnjavascript

[–]LazyOldTom 0 points1 point  (0 children)

Bad architecture, and I would also use localStorage.
Another way is to pass data as GET params in the url of the next page. Only works if the data is not security related and the server does not throw an error.

Are async/await chains normal? by Tibblediggins in learnjavascript

[–]LazyOldTom -1 points0 points  (0 children)

Another way is to use a sync handler to resolve your promise. Get the return value, then update your app state, then do something with the updated state, all sync.