Posts by Augusto Vasques • 15,321 points
571 posts
-
0
votes4
answers265
viewsA: Check if delta is less than zero (Bhaskara’s formula)
If you need to make a comparison with the delta value before showing the roots or not, separate the delta calculation from the root calculation. delta = lambda a, b, c: b**2 - 4*a*c bhaskara =…
pythonanswered Augusto Vasques 15,321 -
3
votes1
answer67
viewsA: I need help with the textContent function
When you consult with selectors using Document.querySelector() is returned only first element within the document corresponds to the specified selector. Because of this your code only operates on…
javascriptanswered Augusto Vasques 15,321 -
4
votes2
answers81
viewsA: Compare two lists without interference of upper and lower case letters
If the goal is just to send the greeting message without having to do any additional configuration action it is possible to use a more functional approach using a lambda expression applied with the…
-
0
votes3
answers1665
viewsA: multiples of 2 and 3 in python
Don’t try to do everything in one operation. Divide your code into small steps: Collect user’s initial data. Create two lists. A list will store multiples of the first number, the second list will…
-
1
votes2
answers159
viewsA: C function that checks whether the whole string is lowercase
Its function bool minusculo(const char * s) will only return true if all alphabetic characters of the entry s. This implies that an alphabetic character of s to return false. Behold: #include…
-
3
votes1
answer135
viewsA: Tranche maturity by period
If you want to stipulate a fixed daily variation between the emission range of your plots this interval should be initially computed in days. Inform the function calcula_parcelas() the interval in…
phpanswered Augusto Vasques 15,321 -
0
votes1
answer161
viewsA: How to use a Python function in Django
My own solution to the question. Actually, it was simpler than I thought. I just needed to call the function to carry out the processes that it would already do and then save this data in the…
python-3.x django django-templates django-rest-framework django-querysetanswered Augusto Vasques 15,321 -
4
votes2
answers151
viewsA: How to simplify this code in Python?
Your code will be simpler using List Comprehension: def group(lista, a): return [list(lista[i:i+a]) for i in range(0, len(lista), a)] print(group(range(0,100),4)) Test the code on Repl.it Upshot:…
pythonanswered Augusto Vasques 15,321 -
2
votes3
answers98
viewsA: How to identify numeric digits in numbers within a list?
One possibility is to use the built-in function filter(função , iterável ) creating an iterator from the elements of iterável for which the função filter, passed in first parameter, return true. The…
-
3
votes1
answer78
viewsA: Opa friends, I wonder why in the code below the answer only comes out right if before writing the word (holy) I give a space. : /
The need for space added at the beginning of the input is due to the misuse of the method str.find() and a disastrous type conversion. The method str.find() returns an integer numeric value (zero or…
python-3.xanswered Augusto Vasques 15,321 -
2
votes3
answers81
viewsA: Confusing behavior in changing the value of variables in js functions
As said in the comments make a table test to understand what program is doing step by step. In this test are four columns Code, goals, output and comment, where: Code: shows the line being executed.…
-
2
votes3
answers55
viewsA: How to use mouse events to create enter/out effect without the German inside the selected element interfering
If you don’t want to use javascript you can do it using CSS only. One pseudo-class CSS is just a keyword added to selectors CSS specifying a special status of the selected item. Use the pseudo-class…
-
2
votes3
answers75
viewsA: how to make Submit be enabled after the text value is greater than x dynamically?
If I understood what you said about dynamic filling what you lack is to fire the event keyup after completing the input. To trigger an event by code use the method EventTarget.dispatchEvent() that…
javascriptanswered Augusto Vasques 15,321 -
2
votes2
answers68
viewsA: I’m learning JS and was testing functions and have a doubt
It makes no sense the existence of the function algorithm messenger(). messenger() is dependent on the external variable txt. The first use of the function detector() is harmless in no way affecting…
-
2
votes1
answer40
viewsA: How to make this code can be used more than six times
Reading the error log is being reported: "message": "Uncaught Invalidstateerror: Failed to execute 'start' on 'Audioscheduledsourcenode': cannot call start more than Once." In other words, there was…
-
3
votes2
answers325
viewsA: How to change the background color of an html table with javascript
First thing I noticed is that your goal is to separate some cells from a table and to color according to the criterion whose situation is assigned to a person. It turns out that the way it addresses…
javascriptanswered Augusto Vasques 15,321 -
1
votes1
answer97
viewsA: Group elements of an array during a loop in php
You can use the function array_chunk() to break your array into blocks of 100 elements. Each of these blocks you can group its elements using the function implode() that joins elements of an array…
-
6
votes3
answers2304
viewsA: Check how many times a number appears in the array
One possibility is to use the method Array.prototype.reduce() performing a reducing function for each element of the Array, resulting in a single return value. In your case reduce() can be used to…
-
6
votes2
answers195
viewsA: Question about entering items in a list with indexes inside Python brackets
Before answering your question you need to know two simple concepts. Subscription and Slicing. Subscription. This syntax of using a pair of brackets [] juxtaposed to an object is called Subscription…
-
9
votes1
answer196
viewsA: The dollar ($) does not work to interpolate a string in Javascript
What you’re looking for is called Template Strings. Template strings is a literal string that allows embedded expressions. This literal is delimited by serious accents ` instead of the traditional…
-
3
votes1
answer105
viewsA: find least repeated value in list
In statistics, the frequency (or absolute frequency) of an event i is the number nᵢ times the event occurred in an experiment or study. That is the amount of times that this value appears in sample.…
-
1
votes3
answers69
viewsA: How to ignore other occurrences like this when capturing a snippet of a string?
Use a regular expression to replace the appropriate portion of text. The class Regex has an overload of the method Replace(String, String, Int32) which allows to define the limit of substructions to…
-
2
votes2
answers66
viewsA: Variable Does Not Change Inside Factory Function
It doesn’t work because it’s a closure, is a function that keeps with itself the lexical environment which defined it. At the time of its definition, the function referenced by addImg contained in…
javascriptanswered Augusto Vasques 15,321 -
0
votes2
answers85
viewsA: Is it possible to change the value of a Readonly with conditions?
If I understand the question correctly there is no problem, the attribute readyonly determines that the element is read-only for the interface. For the script is indifferent. See the example: let a…
-
4
votes1
answer342
viewsA: Date coming with date tomorrow instead of today
Update The original answer was written initially using the method Date.prototype.toLocaleDateString() which could display date and time in the same call. At the time the code was written it worked…
-
3
votes4
answers669
viewsA: How to access indexes backwards within a list?
If your intention is to cycle the indexes of a list on the right, that is to do that when the searched index exceeds the length of the list back to the beginning, just get the rest of the entire…
-
3
votes3
answers444
viewsA: Different results when using != or > in loop condition
There is a noniterative approach to this problem. import math a = 80000 b = 200000 t = math.ceil(math.log(a/b, 1.015 / 1.03)) print(a * 1.03 ** t, b * 1.015 ** t, t) Test in Repl.it To understand, a…
pythonanswered Augusto Vasques 15,321 -
1
votes2
answers115
viewsA: Word most often in a string from a size
I only got the amount of letters per word using the regular expression ^\d+ that searches for one or more digits that start the phrase and then removed the input digits with Slice(). I created a…
javascriptanswered Augusto Vasques 15,321 -
1
votes2
answers678
viewsA: Javascript functions: One function inside the other
First of all yes you can declare in javascript one function within the other. That kind of statement is called Nested Function and is initially accessible only to the scope containing it, but its…
-
3
votes1
answer61
viewsA: How to reorder a list using PHP?
First you have to break the string into its components so you can regroup them. Start by clearing the entrance ends by removing the initial and final spaces with trim(). Then separate the text into…
phpanswered Augusto Vasques 15,321 -
8
votes2
answers189
viewsA: Sum function with a large value returns a wrong result
In Javascript the default type to work with numbers is Number which represents a floating point value of double precision (64 bits) following the standard IEEE 754. According to IEEE 754 only…
-
3
votes2
answers72
viewsA: Problem using push in JS array
Have some problems with the code: There is a syntax error on the line Array.push(element.pass_date_time; You are using a native Javascript type Array as if it were a variable. To solve the syntax…
-
3
votes4
answers312
viewsA: Limit input value with Javascript
What’s missing is actually simplifying the code to then visualize the problem. First I memorized the code and then I took out the elephant ...document.getElementById("quant")... from within s a l…
-
0
votes1
answer128
viewsA: Triggers in Mysql with "Unknown column" errors in the key of a table where these triggers are stored
The field cd_venda does not exist in the table itens_venda therefore the errors within the triggers. Remake the relationships between primary key vendas.cd_venda with the foreign key…
-
3
votes2
answers303
viewsA: How to assign the result of an object breakdown to a variable that contains all unstructured fields?
Yes it is possible to do this in SE6. It is an exclusion selection that combines the dismantling with a parameter Rest. The original object will remain unchanged while the resulting object will be…
-
2
votes1
answer45
viewsA: How do I make the user not paint the svg line on a site to color the same
The problem is because you are installing the event click on the element <svg> in: $("#octocat").click(function(event) { $(event.target).attr('style', _currentFill); }) Install the click event…
-
10
votes1
answer642
viewsA: How do I hold an action key until I release the key
In fact the code presents two immediate problems: The manipulation of keyboard events in the way that is done is not the most efficient to obtain the desired effect. Works well for web applications…
-
8
votes1
answer642
viewsQ: How do I hold an action key until I release the key
In video game games the action displayed when pressing a key is smooth, continuous and immediate. However when implementing a routine that animates a character according to the key pressed using the…
-
3
votes1
answer109
viewsA: Create a variable with the input value and addeventlistener "keypress"
The problem is that you generalized the installation of the same events to all your inputs and when you needed to fetch a value from a specific input you were left with no output... or almost. The…
-
1
votes1
answer59
viewsA: My code doesn’t work!
As I said in the comments are missing some things in your code. First you need to evoke the function main(), it was declared but not used. You also need to attach the created element to the line…
-
2
votes2
answers87
viewsA: How to define which inputs will be accepted by the code?
An alternative solution would be to create a regular expression to validate the input as an integer or floating point number and then use the method ast.literal_eval() to obtain the literal value of…
-
2
votes2
answers58
viewsA: Problem using counter variable within Xmlhttp/AJAX request
When booting XMLHttpRequest through the method open() with only two parameters you are informing the system that you are initiating an asynchronous request. In an asynchronous request the function…
-
7
votes2
answers177
viewsA: How to insert objects using canvas (javascript) and avoid 2 objects in the same position
To detect the collision between two geometries it is necessary to implement a collision test. There is a specific algorithm for the collision test between two figures of arbitrary geometry called…
-
1
votes2
answers218
viewsA: Generate a new array from another with reduce javascript
No need to use the method reduce() to get what you want. Actually it is not the most suitable method to generate a set of objects, in its documentation reduce() is defined like this: The method…
-
2
votes2
answers155
viewsA: How can I do this recursive function
The concept of recursive use is mistaken. In my view in this exercise recursion is asked to functionally iterate through the list elements and discard the first element each new iteration. This…
-
2
votes6
answers444
viewsA: Counting multiples of an integer is giving very different values than expected
An alternative solution to the problem would be to create a numerical list [n1, n2[ and filter their values by passing only the multiples of n1 and count the quantity of those approved values. To…
-
2
votes3
answers124
viewsA: if and Else in Python
The if/else is a conditional selection structure used to divert processing flow between command blocks. Your algorithm is: Se (condição) Então (bloco de código Se) Senão (bloco de código Senão) Fim…
-
2
votes4
answers292
viewsA: How to find the index of an object in a javascript list
An alternative is to use lib Lodash. In that lib there is the method _.isEqual() which makes the comparison between objects independent of the order in which their properties were declared. To get…
javascriptanswered Augusto Vasques 15,321 -
3
votes4
answers823
viewsA: Transform String Array into Object Array
It is not very different from what you did but has the advantage of not having to change the algorithm if you create a different key in the future: let arr = [ "TagFuncao:CN Evento:TODOS",…
-
3
votes2
answers126
viewsA: How to operate on the counter of a while in each loop iteration
You can use comprehensilist on to obtain the value and f-strig to simplify the composition of the text. valor= int(input('digite o numero desejado:')) #No caso 0% e 100% são valores redundante pois…