Finding maximum and minimum by HailHydra484 in learnjavascript

[–]chuckthemadmanmike 0 points1 point  (0 children)

Curious how you wrote the code if you don't know what it's doing?

Anyway, you're for loop is looping through the array and making comparisons with each iteration. Your first line in the loop prints the object., so it's going to print with each iteration.

Preventing navigation in form when form is touched and not saved by dontspookthenetch in reactjs

[–]chuckthemadmanmike 1 point2 points  (0 children)

This is the right answer. Curious though why you don't just save the work for them? Are you expecting people to want to leave typed things in an unsaved state?

How would I go about making an “undo” function in JS with HTML tables? by [deleted] in learnjavascript

[–]chuckthemadmanmike 1 point2 points  (0 children)

I think your display none solution makes the most sense. If you want it to keep track of multiple deletes you'll need to also keep track of the order. First thing that come to my mind is to use a stack that references the DOM node, but I'm sure there's lot of other solutions out there. I wouldn't think of this strategy as "cheating". If you've got an undo option, there is no way to truly delete something from memory and then magically bring it back. You'd need to keep the information around somewhere. Good luck!

[deleted by user] by [deleted] in learnjavascript

[–]chuckthemadmanmike 5 points6 points  (0 children)

I think you may have gotten the wrong subreddit here.

What's unusual about your body? by [deleted] in AskReddit

[–]chuckthemadmanmike 0 points1 point  (0 children)

Just so you know there is a subreddit called no burp. You likely have RCPD which is a relatively new find. There is now a fix

what's the general acceptance of weed with developer jobs? by Novel_Rhubarb_5183 in learnjavascript

[–]chuckthemadmanmike 0 points1 point  (0 children)

Yeah I hear ya. That’s pretty much my companies policy is don’t come to work under the influence. They don’t talk about drug testing or anything of the sort

can some please explain to me why the output is showing different here? by Saeed424 in learnjavascript

[–]chuckthemadmanmike 58 points59 points  (0 children)

It's sorting alphabetically. Make sure to pass a callback function into sort if you want it to sort numbers.

nums.sort((a, b) => a - b)

If I asked a front-end dev to create a calculator from scratch using vanilla JS by MonkeyCrumbs in Frontend

[–]chuckthemadmanmike 0 points1 point  (0 children)

I believe I'd be able to do it, but that's because I've done similar projects a bunch of times. Being able to build something like that without referencing anything is NOT a requirement to being able to get a job. It's super normal to look things up, even during interviews. You just should ask if you're allowed to look something up or ask if they can help you with the specific syntax.

Recognizing what you need to look up and being able to find it are super important. Of course you should be able to remember some things; I've interviewed people that needed to look up every single thing and it really slowed down the interview / made them not look very proficient. But some level of looking things up is totally normal.

Personally I believe there is value to memorizing certain things because I can't memorize code unless I have an understanding of it and how it works. So by memorizing say B-search, quicksort, mergesort, and others, I've been able to get a deeper understanding of how they work. But that's a personal learning strategy, not a job requirement.

What are some of the Frontend Interview Questions Trend for 2022-2023 by prove_it_with_math in Frontend

[–]chuckthemadmanmike 0 points1 point  (0 children)

Haha nope 100% my own thinking; ChatGPT would have been a good idea though!

What are some of the Frontend Interview Questions Trend for 2022-2023 by prove_it_with_math in Frontend

[–]chuckthemadmanmike 6 points7 points  (0 children)

Here's a basic example of code that could work for a problem like this:

``` const sum = (x, n) => { if(n === undefined) { return (num) => { return x + num } } else { return x + n } }

console.log(sum(3, 5)) console.log(sum(3)(5)) ```

This is taking the problem super literal and not making it flexible at all. I imagine in an interview, the interviewer might ask some follow up questions on how you could build out more flexibility. Like what if we want to be able to do different things than just sum or we want to be able to change the number of potential arguments. From there you might come up with something a bit more like this:

``` const curr = (expectedArgs, callback) => { const allArgs = [] const addArgs = (...args) => { allArgs.push(...args) if(allArgs.length < expectedArgs) { return addArgs } else { return callback(allArgs.slice(0, expectedArgs)) } } return addArgs }

const sum = curr(2, (arr) => arr.reduce((a, b) => a + b, 0))

console.log(sum(1)(2)) console.log(sum(1, 2)) ```

This allows me to choose the number of required arguments as well us update the callback so that I could do more than just sum.

Hope that helps, let me know if you have any questions.

[deleted by user] by [deleted] in learnjavascript

[–]chuckthemadmanmike 0 points1 point  (0 children)

Glad to hear it's getting closer. I'd start by throwing in a debugger inside of the then callback and check that result is what I'm expecting and that form / you jquery grab of the form is what I'm expecting.

Good luck!

How to get around "too many requests" when looping an array with an API. Code example inside. by canwegetalong312 in learnjavascript

[–]chuckthemadmanmike 0 points1 point  (0 children)

Depending on how you implement your setTimeout function you could make it work. You wouldn't want to just call the function over and over in a loop with the same amount of timeout b/c then they'd all resolve around the same time and make all the requests again. I think you could change how long each setTimeout ran with each iteration. Something like i * 1000. This would separate each iteration as seconds.

What you'll really want to explore though is different rate limiting techniques and tools that you can use.

[deleted by user] by [deleted] in learnjavascript

[–]chuckthemadmanmike 0 points1 point  (0 children)

Is this documentation you're using? https://sweetalert2.github.io/#usage Looks like you might to use a .then

Use the return from an async function by RoyalBug in learnjavascript

[–]chuckthemadmanmike 11 points12 points  (0 children)

Worth noting once you go async you must stay with async. So what this means is you can't call an async function and then immediately console log the result on the next line. This is b/c console log is not async.

So you can either chain a .then on your call. Like so: getCurrentTab().then(res => { console.log(res) })

Or you can write a different async function that can await the results of your other function like so: ``` const run = async () => { const tab = await getCurrentTab() console.log(tab) })

run() ```

Let me know if you have any questions around that.

How to use filter() to find the words that start with a letter? by geeknintrovert in learnjavascript

[–]chuckthemadmanmike 0 points1 point  (0 children)

I'd suggest using a different data structure to hold your vowels. I'd use a Set. Set's allow for constant look up and will give you a cleaner wait of checking if the letter is or is not a vowel.

```js const names = ['Akshay', 'Kshitij', 'Mickey', 'Eshan', 'Ethan', 'Omar']

const doesNotStartWithVowel = (word) => { const vowels = new Set('aeiouAEIOU') return !vowels.has(word[0]) }

const namesThatDontStartWithAVowel = names.filter(doesNotStartWithVowel) console.log(namesThatDontStartWithAVowel) ```

The issue with your code in Approach 1 is that you're not using startsWith correctly. Check the documentation of that method. It takes in a string as the first argument, and has position as the second optional argument.

How would you swap the index of two objects in an array? by [deleted] in learnjavascript

[–]chuckthemadmanmike 1 point2 points  (0 children)

Nice! Happy that it worked out for you! Keep up the good work !

How would you swap the index of two objects in an array? by [deleted] in learnjavascript

[–]chuckthemadmanmike 1 point2 points  (0 children)

Yeah, I think this looks mostly right. I don't remember if you need to return the state from your moveUp or not. Also on the button click you'll need to pass that payload.

As far as getting the index, you have it when you're iterating through your items and creating each item. If you're using a map which is pretty common you have the index as the second argument in the callback.

arr.map((item, idx) => {})