Posts by hkotsubo • 55,826 points
1,422 posts
-
2
votes1
answer1069
viewsA: How to count repeated items with javascript?
Do not use map, He’s not cut out for it. map serves to transform array elements into something else. For example: let x = [1, 2, 3]; console.log(x.map(n => n * 2)); // imprime o dobro dos números…
-
7
votes2
answers68
viewsA: Can’t print objects using template string?
When you do console.log('Novo Obj ', obj), is passing the object as one of the arguments of console.log (the comma separates the arguments, then the string 'Novo Obj' is the first argument, and the…
javascriptanswered hkotsubo 55,826 -
11
votes3
answers246
viewsA: What is the point of using scripts in links?
Why it exists, is there any reason why it still works? Let’s go in pieces... URI Schemes The value javascript:código JavaScript is a URI that uses the URI Scheme javascript. Basically, there are…
-
3
votes1
answer181
viewsA: How to convert a character to its corresponding hexadecimal in the ASCII Ruby table?
You can use the method codepoints, which returns an array with the numeric values corresponding to the characters of the string, and then just convert them to the desired format: puts…
-
0
votes1
answer44
views -
0
votes1
answer55
viewsA: How to Make the following function in pure javascript?
The problem is you’re getting the value atraso.value out of function calc. Then this value is loaded only once, when the page loads, and is never updated. If the idea is to take what has been…
-
7
votes4
answers798
viewsA: Search id in object array with Javascript
find returns only the first element found. But as the result may have more than one, an alternative is to use filter. And as the criterion is "one of the technologies must have id 6", just use find…
javascriptanswered hkotsubo 55,826 -
5
votes2
answers2009
viewsA: Javascript - How to calculate average data in an array with multiple objects and return in another array
The problem is that you’re adding up all the students' grades, and you’re also dividing by the amount of grades in the middle of the loop (which doesn’t make sense, because to calculate the average…
-
7
votes3
answers146
viewsA: How to use double quotes in a python application by running a subprocess
Your string cmd contains this: echo "network={ ssid="jimi" psk="yay" key_mgmt=WPA-PSK }" >> /etc/wpa_supplicant/wpa_supplicant.conf And when you run this command, the quotes are ignored. For…
-
2
votes2
answers923
viewsA: What is the difference between querySelectorAll() and getElementsByClassName()
The main differences are basically two: getElementsByClassName only searches by class name, while querySelectorAll searches for any valid selector - this includes searching for the id, by the name…
-
6
votes2
answers147
viewsA: In Java because (250 >> 4) is more optimized than (250 / 16)
Just to be pedantic and clarify what was said in the comments, the >> is an operator bit shift (in this oracle tutorial the separation between operators is clear bitwise - and (&), or (|),…
-
2
votes1
answer64
viewsA: Regex: how to select whole sentence (no digits) and insert quotation marks
It would be easier to use some language to read the CSV, separate the fields and create the Inserts, but if you want to do with regex, come on. One option is to use (\d+)\s+(.+): \d+: one or more…
-
1
votes2
answers174
viewsA: How to create class correctly with pandas by applying methods?
__init__ is the constructor and it serves to initialize the instance being created. You should not return anything from it, it makes no sense. It should only do what is necessary to create a valid…
-
1
votes1
answer1084
viewsA: Sum of the elements of the secondary diagonal of a matrix
I don’t know if it was a typo, but you created the method somaDiagonal within of the method main. Forget it. Or create a method outside the main, or do not use the method and put all the code in…
-
1
votes2
answers67
viewsA: Sum of 3 matrices in a new matrix
You can only add matrices of the same size. If you have a matrix M x N (with M rows and N columns), you can only add it with another matrix M x N, and the result will be another matrix M x N. That…
-
1
votes4
answers65
viewsA: I cannot print a list(vector)
Instead of inserting the digits at the bottom of the list and then reversing it, why not always insert the new elements at the beginning of the list? So they’re already in the right order. Just…
-
0
votes3
answers92
viewsA: Error using case clause inside a Where
Just one detail, in your query the first condition of WHERE is ST.cod_sistema = 'LS'. I mean, you’re just picking up the records with cod_sistema equal to "LS". Therefore, no CASE it no longer makes…
-
7
votes2
answers337
viewsA: How do "for in, for of, foreach" loops traverse the array?
for..in The for..in iterate on the enumerable properties of an object, as long as the keys are strings (because the keys can also be Symbol's). Note that this is true for any object, not just…
-
1
votes1
answer149
viewsA: Select data according to a specific time
An alternative is to store the available schedules and the respective doctors in a dictionary. A suggestion is to have this structure: from datetime import datetime, time # dias da semana: 0 -…
-
2
votes2
answers170
viewsA: How to place two arrays inside a single loop of repetition to populate an object?
If the structure at all times is this, with the paragraphs inside the tags a, then you don’t need to build two arrays to then make one loop in both. Just search for tags only p and access the a…
-
4
votes2
answers63
viewsA: Would you like to know how to build a function that counts repeated numeric values in an array?
First you need to save how many times each element occurs. For this you can use an object whose keys are the array numbers, and the respective values are the number of occurrences. Then you have to…
javascriptanswered hkotsubo 55,826 -
0
votes1
answer3700
viewsA: Program C calculating ages based on date of birth
You will only know who is the oldest person after calculating everyone’s age. So it makes no sense to try to print the respective message inside the for. In the for you should keep the age of…
-
1
votes1
answer348
viewsA: How to do for instantiating a new JAVA object
First, if the class should represent a computer, then I suggest it has a proper name (Computador, maybe? ) - although it seems a silly detail, giving better names helps a lot when programming. And I…
-
3
votes1
answer47
viewsA: If B is a subtype of A, why is a collection of B not a subtype of a collection of A?
This is because inheritance in collections does not work the same way it works with classes. In oracle tutorial it is mentioned that: In general, if Foo is a subtype (subclass or subinterface) of…
-
3
votes1
answer64
viewsA: Calculate 2 different array element totals according to the value of another property
You have already created the functions to filter men and women, another to map each employee with their respective salary and another to calculate the sum of the elements of an array. Just needed to…
-
1
votes1
answer72
viewsA: How to use find in find_all result
This is because find_all returns a list of elements, but find can only be called from one element. And how find only returns a single element, that’s why the second code works (the first find search…
-
5
votes2
answers119
viewsA: How to use 'Else if' correctly?
The = is the allocation operator, then a = b is actually setting the value of the variable a, which becomes the same value as b. Then this value is tested according to those rules (and as any…
-
0
votes2
answers116
viewsA: Read multiple tag attribute in an XML
If you want to make a loop by all tags product, just do: $feed = simplexml_load_file($url); foreach($feed->children() as $item) { if($item->getName() == 'product') // somente se for product,…
-
1
votes1
answer24
viewsA: Error in using Mockito. Actually, there Were zero interactions with this mock
You have to call the when before to call the method being tested: Mockito.when(dao.obterAtrasados()).thenReturn(pendentes); service.notificarLocacaoEmAtraso();…
-
0
votes1
answer92
viewsA: error while trying to change a table by adding a new column of type datetime in mysql
How you created a column that is NOT NULL, it has to have some value. As you did not indicate the value default, is used the "implicit default value", which in this case is "zero". Then you’d have…
-
1
votes1
answer62
viewsA: How to stop an interval with clearInterval and continue it later?
The problem, in my view, is that you are mixing different responsibilities in the same roles. For example, the function that chooses the random word is also responsible for updating the count, has…
-
3
votes1
answer63
viewsA: How to apply capitalization in paragraph text with specific classes directly in the page body?
If you want to change the innerHTML of each of the elements, just use the result of querySelectorAll (that returns a list of the elements), travel around and change the innerHTML these in the…
-
1
votes1
answer63
viewsA: Looking for string inside another Python string
I think I’ve mentioned another question from you, that for is wrong: for linha in arquivo: lista = linha.strip('[]').strip('\n') In this way, the variable lista is overwritten with each iteration of…
-
1
votes1
answer398
viewsA: Calculation of cubic root in vectors
If you want the cubic root, it’s no use doing sqrt(sqrt(numero)), for the square root of the square root is the fourth root. There is no function ready for the cubic root, but we know that the root…
-
2
votes2
answers75
viewsA: Extract the price of a text and show it formatted
If the text at all times has this format, so just take the snippets "R$ etc": function formatar($preco) { return number_format(str_replace('.', '', $preco), 2, '.', ''); } $texto = 'Melhor preço sem…
-
0
votes2
answers454
viewsA: Percentage with if in Python
Only to complement the another answer: In the elif no need to test whether PRODUTO >= LIMITE * 0.6. If you didn’t get into the if PRODUTO < LIMITE * 0.60, is because the product is not less…
-
5
votes1
answer74
viewsA: Use reduce() method to reorder object array!
Maybe it’s easier - at least I think - to do without reduce. Just make a loop simple by array old and go riding the new object: const old = [ { id: 1, date: '2020-08-27T00:00:00', title: 'Title 1'…
javascriptanswered hkotsubo 55,826 -
1
votes1
answer85
viewsA: Problem reading strings and numbers in sequence with Scanner
The problem happens because of that here. Basically, nextInt only reads the minimum required to have an integer number. So it does not consume line break (the ENTER that the user types), and this is…
-
0
votes2
answers205
viewsA: Copy line and write the same line to another file using python
First of all, readlines reads all the lines of the file, returning them in a list. But since you only want the second line, you don’t have to read them all: with open(arqfasta) as leitura,…
-
2
votes1
answer67
viewsA: Comparing strings
First of all, it’s wrong around here: for linha in arquivo: lista = linha You read all lines of the file, but with each iteration you override the value of lista. At the end, she’ll only have the…
-
4
votes1
answer76
viewsA: Java Array Storage Error
You created the array with zero size. The fact that you changed the value of the variable tamanhoVetor then does not cause the array to change size. So, first read the size and then create the…
-
3
votes1
answer48
viewsA: Creating Date by passing numbers has different result from passing a string with the same values
When you call the builder passing numbers, the month is indexed at zero (January is zero, February is 1, etc). So new Date(2018, 02, 20) corresponds to March 20. If you want February 20, do new…
-
1
votes1
answer71
viewsA: Error picking value returned with query.getResultList(). get(0)
A cast is only possible when the types involved are compatible with each other, that is, when one is a subtype of another. For example: class Animal { etc... } class Gato extends Animal { // só gato…
-
1
votes2
answers38
viewsA: I would like to know how to get the value of the amount of commutations in a list sort. without using Sorted()
Just create a variable to count, and increment it when you have a trade: s = [2, 4, 3, 1, 6, 7, 5, 8] cont = 0 for i in range(len(s)): for j in range(i+1,len(s)): if s[i] > s[j]: s[i], s[j] =…
-
0
votes2
answers290
viewsA: When printing an array elements are not shown
linha is an array of String's, and when you print an array with System.out.println(array), internally is called the method toString() of the same. Only that arrays inherit this method of Object,…
-
2
votes2
answers95
viewsA: How to store value in a variable and return its primitive type and other information
When you do: print('{} é', type(n1), 'além disso, ele é'.format(n1)) You’re passing 3 arguments to print, since they are separated by comma: the string '{} é' the result of type(n1) the result of…
-
1
votes2
answers172
viewsA: Python Generate txt layout from a txt file
The problem is that you are reading the entire file and then just save the last line on new (because she’s out of the for who reads the file, and after the for the variable s will have the last line…
-
0
votes2
answers72
viewsA: Python does not advance and does not present an error after converting string to float, how to resolve?
The problem is that you are concatenating a string with a number, but you can only concatenate with another string. Only instead of turning the number into a string, as suggested another answer, you…
-
2
votes1
answer114
viewsA: How to convert hexadecimal to decimal received by socket
Server When you call the method print of a PrintStream passing an array of bytes, it ends up calling this version of the method, which according to the documentation writes the result of…
-
0
votes2
answers43
viewsA: Why can’t I use Stringbuilder’s delete() method more than once in the same code block?
There are several problems there. The first has already been indicated in another answer: indexOf returns the index where begins the occurrence of substring. That is, conteudo.indexOf("fimprog")…