A program to count zero spots for a function - javascript

so I wrote the program what will count the zero spots on the quadratic function however I do not really know how would I run it:
Sorry for posting a picture instead of putting a code here but damn stack overflow is causing my a troubles with posting.

Related

Best way to orchestrate a sequence of events based on user input in a browser game?

I really struggled to phrase the title, which shows how lost I am. I consider myself a good web developer, but structures like this break my head :D
–––
The game
I'm remaking a little ear-training game of mine (http://twelvenotes.co/) with Nuxt3.
The game features 8 rounds of questions. Each round plays 2 musical notes and the player must tell which one is higher.
The interactive concept for the new version has changed. The game does not start automatically, but waits for a "Start now" input from the Playeyr. Each round the two notes play automatically in sequence. The Player has two options now:
Click on one note to lock in the answer to which note he thinks is higher
Replay the two notes in the same sequence, but lose "1 life" (or "extra listen") of 3
Answering a question shows an animation indicating if Player is right or wrong. After the animation is completed the game should move to the next round automatically and also start the round automatically, after the animated transition to the new round is done.
The whole game and each round individually is timed with a visible stop watch which will influence the final score.
After 8 rounds the Player is presented with an end screen showing the performance and a score.
The problem
As of right now, Creating the array of playable rounds, locking in the answer, moving to the next round, playing notes, replaying notes are all separate functions.
Now to the question: Whats the best way to control all these functions? Especially with timeouts needed for animations and playing notes etc. it's hard to structure which function does what and who tells it when to do it.
Who controls when we move to the next round and when we will start that round? Moving to the next round should only be possible when the current round has been answered. But should all of this be the job of moveToNextRound()? And who actually starts the round as in playing the notes, starting a stopwatch for this round etc. – And who stops the timer of the played round when the round has been answered? Is that a job for moveToNextRound() or startRound(roundIndex) or is that the job of a new function finishRound() - but who then calls finishRound()? Or should it be finishCurrentRound(). When a question is answered we need time for an animation telling the player if his answer was right or not and so on and so forth...
... I guess you get the picture. Structuring this is not easy for me. While doing it I constantly go back and forth between which function does what.
The question
Can you guys point me to best practices or resources in that field? Only thing I can think of googling is: "Gamecontroller"... which obviously only gives you results for gaming console gamepads.
Thanks!

Why my javascript code is failing in performance test cases of code challenge?

Code challenge question, my solution and result of test cases can be found in the link below
https://app.codility.com/cert/view/cert7ETU9Q-AA9D2MAVP43AR4WP/details/
Can you please review it and tell why my solution is failing in performance testcases? and how my solution can be improved?
Thanks
You are computing maxes at every iteration (using Math.max), which gives a quadratic time algorithm. However, once you have max of the heights of the first k buildings, you can update it in constant time (is the last building taller than the max?) You can do right to left maxes similarly - this will give you a linear time algorithm for the problem.

Wild time differences measured in Node.js program

I've noticed an odd behavior in a program I am working on. While it's probably my fault, I wanted to check if someone faced this before.
Both with console.time and performance-now my code has highly variable run time. I can't exactly paste it here because it's work related, but the workflow is:
start timer
load image via jimp
when image is loaded, scale image times 2
scan the image, transform pixels in zeroes and ones and put it into an array
log time
Some discrepancy is sure to be expected, but the results are so different I'm wondering what I did wrong. Average time is short, but the outliers are pretty... well, you can see on the image below.

JavaScript Canvas requestAnimationFrame freezing tab

I've been working on a 2D game in JavaScript using the canvas, and I found that requestAnimationFrame seems to make the game much smoother, which is great. However, the game has been freezing at random times ever since. The tab becomes stuck, and the game doesn't throw any errors, so I'm kind of at a loss. I have tried many things to manually debug it, such as constantly updating a LocalStorage variable, just displaying in the console, etc. Nothing is really giving me any results.
I can say that my experiments lead me to believe that there may be some strange asynchronous behavior associated with requestAnimationFrame; namely, I have noticed that if I change the size of something via socket.on, such as an array, and the game happens to be running a for-loop on that array, it sometimes crashes mid for-loop saying that the thing I'm referencing is undefined, even though I check for that right before the for-loop. Moreover, I noticed that when requestAnimationFrame calls code, such as my Game.update() function, sometimes the "this" object isn't properly referencing the object I'm in. ie., in Game.update(), this.draw_something() would throw an error. I have fixed those issues I believe, but I'm wondering if anyone has any insight into the overall nature of requestAnimationFrame.
The last thing I want to mention is that when the tab freezes, the memory begins to sky-rocket. It quickly goes from a few hundred MBs (from pre-loaded gfx, etc) to around 2 gigs, and continually increases.
I hope someone has some good feedback - and thanks in advance.

Space Invaders ASCII, shoot stops

I'm doing some work for a class, and I'm building space invaders game in ASCII.
I know that I can do better code, using objects, but in my case I can't use it!
I also know that I have others errors on code, but I only want to know an answer!
When I shoot (pressing space), and then I shoot again and if the first shoot isn't collide with a alien, the first shoot just stops! and I really don't know why!
I have comments and vars in Portuguese, but if you don't understand something, just ask!
Code: http://pastie.org/private/fbnjo8vczkxq6quoem6tig
online: http://www.tomahock.com/Projecto-LabMM3/spaceInvaders.html
P.S. I know that isn't the best code ever! And it is an alpha version lots to do yet!
You should maintain a list of projectiles and update the entire list each game iteration. It looks like you are only updating the current projectile, and once you shoot one it ignores all previous ones even though they should be updated. That means each iteration you must check for collisions, update location, and check for off of screen for every projectile in the list.

Categories

Resources