Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 days ago.
Improve this question
Can someone help me figure out why naming a variable changes the random value so much? I'm stumped.
In the first picture, you can see that the maximum value of the X value will be a random value between 25 and 300. However, EVER TIME I run the code, the lines are super short.
When I make a top_limit variable, shown in the second picture, the lines have true random lengths.
Can someone shed some light on what's happening here? There's no difference between the two pieces of code, in my opinion. One just has a variable name and the other doesn't. No?
When your random is in a for(,,), it is called on every iteration of the loop. So, in each iteration it changes.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Having a hard time with Regex.
What would be the regex for finding a file name with variable in between them?
For eg:
File name : DON_2010_JOE_1222022.txt
In the above file name the words DON, JOE and the format .txt will remain constant. Rest numbers might change for every file. There could be characters as well instead of numbers in those two places.
What im looking for is basically something like DON_*_JOE_*.txt with * being whatever it could be.
Can someone please help me with this?
I tried DON_*_JOE_*.txt and obviously it did not work.
DON_(?<firstString>.*)_JOE_(?<secondString>.*).txt
You can use this. To access the specific group, you can use matcher.group("firstString").
In JavaScript:
"DON_2010_JOE_1222022.txt".match(/DON_.+_JOE_.+\.txt/)
whatever it could be
It is .+ except new lines.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I have an API which returns a list of objects. Each of these objects have a field called timeOut which contains some time interval in secs. Once the time interval of any object expires, some operation needs to performed on that particular object.
How can I achieve this in react ? I considered using setInterval on each object in the list, but it looks like a bad design.
Any help will be appreciated. Thank you.
You should use setTimeout instead of setInterval if you want an operation to run only once after the given time period. I believe this is your best bet to accomplish this task.
Otherwise, you will have to dive into even crazier designs like comparing the present date-time object from new Date() with the one you generated right after fetching your data, which will not only be complicated but also, more error-prone and inaccurate.
Let me know if you want help with the first method.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have an array of objects in Javascript (I use Vue.js2 in my project) and with .splice I can easily delete all the elements inside of it. The problem is, when only one element remains, I can't delete it because it stays there no matter what.
The easiest way to clean up an array is to make it [array].length = 0
You can use .length, .filter, .pop and im pretty sure you can .splice the last element, maybe there is something else u havent noticed yet.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
X=(x=== images.length-1) ? 0 : x+ 1;
Please help me I have no idea, and it's for a school task that I have to hand in.
I'm not sure why people are so opposed to just answering the question. It's a ternary operation. It's a shortcut for an if/else clause. For this particular operation,
Is x equivalent (===) to images.length-1? If so, set X to 0. Otherwise, set X to x + 1.
This pattern is likely used to endlessly iterate over an array (images). Once it reaches the end, it resets to the first element in the array.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
So I wish to loop the javascript going to a certain page (without actually reloading/clearing console), then execute
href="javascript:doSomething(9)"
and then loop that by doing a function
Please help, thanks!
Assuming you want it to repeat - you can use an interval.
setInterval(function(){
doSomething(9);
},100); // the 100 is for 100 miliseconds
If you want it to repeat without having to wait (that is, block the code) you can use a normal while loop:
while(true){ // will loop forever since the condition is always "true"
doSomething(9);
}