Posts by Sorack • 27,430 points
864 posts
-
2
votes8
answers794
viewsA: Mapping an array with possible subarrays as elements
Update 2021 You can use the method flat of array: const array = [1,2,3,4,5, [1,3,2,4,1]]; console.log(array.flat()); flat The method flat() creates a new array with all sub-arrays elements…
-
4
votes2
answers42
viewsA: Compare the data of an Arraylist not to let register in duplicity - Java
If you do not want your list to contain duplicate elements, the correct collection to use is Set. How your code does not contemplate the creation of the variable prodList, I will make the following…
-
0
votes1
answer37
viewsA: Find out clicked object id
Simply pass an element reference as a parameter using the this. A simplified example of the use is the following: const clicar = (id) => { console.log(`Elemento ${id} foi clicado`); }; <button…
javascriptanswered Sorack 27,430 -
0
votes1
answer37
viewsA: How to use SUM in a multi-return code?
To show them line by line simply remove the while and add a CASE verifying the month in question: SELECT SUM(CASE MONTH(dateEarnCreate) WHEN 1 THEN valueEarn ELSE 0 END) AS monthValue1, SUM(CASE…
-
1
votes1
answer50
viewsA: How do I get my bot to acknowledge that the user sent an image?
In the documentation of discord.js it is said that there is a property attachments in the received message. You can, for example, list the images with the code below:…
-
1
votes1
answer45
viewsA: Help with Select adding up accounts to pay and receive fields for MYSQL reporting
You can use the following strategy: Instead of using a String empty for the Credito and Debito, use 0, so you can use them as a calculation attribute; It covers all your query in a subquery; Use the…
-
3
votes2
answers172
viewsA: How to scrape Qlikview tables using Nodejs?
You can click the button Imprimir using the selector div[title=Imprimir. After that a new tab with the data will open, just select this tab and the function Page.evaluate to fetch the data you want…
-
2
votes1
answer52
viewsA: Object key is not recognized after using fetch
You have two problems in the roles you presented: At no time do you return the value in your function swapiGet; The return of fetch is a Promise, so you should wait for it before using. const…
-
2
votes2
answers35
viewsA: SQL SERVER - Changing different records in a field based on another field
SELECT CODIGO_PARCEIRO, MAX(NOME_PARCEIRO) AS NOME_PARCEIRO FROM VW_DM_REPORTS WHERE CODIGO_PARCEIRO = '27179922000164' GROUP BY CODIGO_PARCEIRO MAX Returns the maximum value in the expression.…
-
2
votes2
answers130
viewsA: Separate String in Java Character
Your first debt String using the method split: String vetor[] = mensagem.split(""); What happens is that you are showing each character separately, showing a message for each. If you are using a…
-
2
votes2
answers115
viewsA: Join two arrays if field is equal in both
The function some returns a boolean. How you want to find the value, the most indicated is to use the function find: const exams = [ { "id": 1, "title": "Avaliação - Procedimento em Serras",…
-
0
votes1
answer23
viewsA: How can I get the value of a span tag with jsoup?
Just run the method text(): System.out.println(doc.getElementsByClass("value").get(0).text());
-
0
votes2
answers44
viewsA: Improve select SQL Server performance
You can create an index in the table by sorting column: CREATE INDEX idx_cliente_cpfcgc ON cad_cliente(cd_cpfcgc);
-
0
votes2
answers40
viewsA: Select in two tables with Count
You can use a subquery in the WHERE to check how many records you have in the table clientes with the category of the line in question: SELECT cat.nome FROM categorias cat WHERE 10 <= (SELECT…
-
0
votes1
answer27
viewsA: Failed to load images in npm package development
In the path of your image, use the function path.normalize: const path = require('path'); ... if (fileSystem.statSync(path.normalize('../assets/bandeira_master_card.png')).isFile()) { ...…
-
1
votes2
answers70
viewsA: Problem adding elements to the array
The problem is that in the method adicionar you roam the countryside lista filling with the String passed as parameter, then when the method is called for the second time overwrites what was in the…
-
4
votes3
answers90
viewsA: Group array of emails by domain of each email in Javascript
You can use the function reduce to iterate on the array and assemble the object with the groups: const emails = [ "[email protected]", "[email protected]", "[email protected]", "[email protected]"…
-
2
votes1
answer52
viewsA: How to make a LIKE IN equivalent to PROCV
SELECT t1.razao_social, t2.nome_fantasia FROM tabela_01 t1 INNER JOIN tabela_02 t2 ON t2.nome_fantasia LIKE '%' + t1.razao_social + '%'
-
1
votes1
answer90
viewsA: How to limit rows per month in SQL
You can solve using ROW_NUMBER together with WITH: WITH totais AS ( SELECT DATE_FORMAT(c.data_compra, "%b") AS mes, c.nome, COUNT(c.nome) AS total FROM compras c GROUP BY DATE_FORMAT(c.data_compra,…
-
3
votes2
answers132
viewsA: Convert JSON to Array
let result = {"0":4,"10":4,"30":6,"60":9,"90":12,"120":15,"150":18,"180":21}; const transformation = Object.entries(result).map(([key, value]) => ({ [key]: value })); console.log(transformation);…
-
4
votes3
answers283
viewsA: How to delete duplicates between multiple tables
One way is to add an index with the column you want to keep as single by adding the clause IGNORE that will delete possible errors and warnings and delete lines that do not obey the created index:…
-
1
votes1
answer28
viewsA: Passport js error in Node
You are using passport on the line: require('./config/passport')(passport) Before the line you define passport: const passport = require('./config/passport') Note: I don’t know the invocation of…
-
2
votes1
answer37
viewsA: Single line query result
SELECT SUM(CASE WHEN ano = 2010 THEN populacao ELSE 0 END) AS a2010, SUM(CASE WHEN ano = 2011 THEN populacao ELSE 0 END) AS a2011 FROM populacao WHERE…
-
2
votes1
answer33
viewsA: Query Transformation
If you want to create a new table based on the data of a query, use the clause INTO: SELECT campo1, campo2, campo3 INTO nova_tabela FROM tabela SELECT - Clause INTO SELECT…INTO creates a table in…
-
0
votes1
answer39
viewsA: SELECT GROUP BY SHOP
You use a WITH together with ROW_NUMBER to obtain the latest data: WITH vendas AS ( SELECT ROW_NUMBER OVER(PARTITION BY io.codloja ORDER BY o.datafechamento DESC) AS posicao io.CodLoja, io.NumOrc,…
-
1
votes1
answer28
viewsA: Error when trying to identify if a string is equal to one of the values of an array
To check whether a string is contained in a array you can use the function includes of array: ... if (types.includes(type))... ... includes The method includes() determines whether a array contains…
-
3
votes1
answer152
viewsA: How to add numbers in sequence in Javascript
Basically your algorithm has 2 errors: Does not increment the result but creates a new value; Returns inside the repeat loop. By correcting these mistakes we would have: function somatotal(numero) {…
javascriptanswered Sorack 27,430 -
1
votes3
answers105
viewsA: How to access item in Arraylist
Just use a stream together with sum: double soma = items.stream() .mapToDouble(item -> item.getQuantidade() * item.getPreco()) .sum(); Remember to encapsulate the amount with private and create…
-
0
votes1
answer19
viewsA: Create a precedent that when you enter a date, it returns the day of the week corresponding to the date you entered. MYSQL
You can use the function DATEPART to get the day of the week: DATEPART(WEEKDAY, '2007-04-21 ') DATEPART - Arguments week and weekday of datepart This function returns an integer representing the…
-
2
votes1
answer185
viewsA: Select elements randomly from an array without repeating
Have you ever thought of just creating a copy of your array and sort randomly? const desordenar = (arr) => { const copia = [...arr]; for (let i = copia.length - 1; i > 0; i--) { let j =…
javascriptanswered Sorack 27,430 -
0
votes1
answer122
viewsA: Mask.js:5 Uncaught Typeerror: v_fun is not a Function
The problem is that when you relate cep in the onkeypress, the browser interprets as input with the id cep. Change the function cep for aplicarMascaraCEP: ... function aplicarMascaraCEP(v){ ... And…
-
2
votes1
answer130
viewsA: How to change a specific value of a string in an array?
Simply use a regular expression replacement in conjunction with the function map of Array: let arr = ['Feijao, Arroz', 'Melancia', 'Banana', 'Laranja,Uva']; arr = arr.map((item) =>…
-
2
votes1
answer95
viewsA: How to access a given object within JSON via Axios
In case, apparently, you want to get the data contained in JSON within the JavaScript. For this it is enough to unstructure the object: const resposta = { "status": "success", "url": {…
-
1
votes2
answers169
viewsA: How to Make a Scan in SQL
SELECT t1.id CASE cpf_valido WHEN 1 THEN (SELECT MAX(t2.id) FROM tabela t2 WHERE t2.cpf = t1.cpf) ELSE t1.id END AS id_para, t1.cpf FROM tabela t1 …
-
0
votes1
answer31
viewsA: Help with SQL query - delete a field/ occurrence
Present the names of managers who have never worked on projects, and manage them. SELECT DISTINCT pes.primeiro_nome, pes.ultimo_nome FROM pessoa pes INNER JOIN projeto prj ON prj.pessoa_gerente_id =…
-
2
votes1
answer191
viewsA: Run javascript function in parallel
The documentation says the following: allSettled The method Promise.allSettled() returns a promise that is resolved after all given promises have been resolved or rejected, with a array of objects…
-
0
votes1
answer115
viewsA: how do you take a jquery value and store it in a variable?
To take the value of one input with the JQuery just use the function .val(): const valor = $('#qt1').val(); In your case I deduce that the button + will not read the value but add a new one input…
-
2
votes3
answers171
viewsA: Trying to manipulate a JSON with JS
If you just want to copy the file to another: const { createReadStream, createWriteStream } = require('fs'); createReadStream('index.json').pipe(createWriteStream('writeMe.json')); It makes no…
-
1
votes6
answers1811
viewsA: Loop Array - Fruit
Your code has some problems considering the enunciation of the exercise: You are using an assignment operator (=) instead of comparison (== or ===) to check if the fruit is in the desired content;…
-
4
votes0
answers147
viewsQ: How to change the basis of a branch?
I have a branch derived from master, development, that never comes back to master. All the branchs of features are derivatives of development, but after tested and validated, are combined both with…
-
3
votes1
answer101
viewsA: How to consume Event-stream with nodejs
Like bfavaretto quoted, you need to consume little by little to form the complete answer. Just use the events: // ... const partes = []; res.on('data', (parte) => partes.push(parte));…
-
6
votes2
answers108
viewsA: Access variable item in JSON using Node.js
You can use the function Object.values() to obtain the values of an object: const resposta = { by: 'symbol', valid_key: true, results: { PETR4: { symbol: 'PETR4', name: 'Petróleo Brasileiro S.A. -…
-
3
votes1
answer66
viewsA: While to Analyze Select Return
To iterate on a result of a SELECT use a CURSOR. Applied in your example would look like this: CREATE PROCEDURE curdemo() BEGIN DECLARE done INT DEFAULT FALSE; DECLARE id INT; DECLARE nome CHAR(16);…
-
1
votes3
answers70
viewsA: First decrement in Javascript with post-decrement operator ("number-") differs from "number - 1"
According to the documentation, when used as suffix, the decrement operator returns the value before of the operation and, when used as prefix, returns the value afterward to decrease. Decrement let…
-
1
votes1
answer254
views -
1
votes2
answers47
viewsA: Check if there is a value in Node JS
From the version 14.0 of Node.js you can use the optional chaining to directly obtain the value you need: const data = { '$instance': { numeropessoas: [{ x: 'x' }] }, numeropessoas: ['2'] };…
-
1
votes1
answer300
viewsA: SQL - Insert random values into a table
Just use the function RAND to select a random integer value from a table. In the following example I created the table valores with an identification column (id) and with a column valor with the…
-
1
votes1
answer69
viewsA: Find a best-selling item along with another
SELECT TOP(1) p.descricao, SUM(i.quantidade) AS quantidade_total FROM ttcupomfiscalitem i INNER JOIN tcprodutos p ON p.produto = i.produto WHERE i.produto <> '222110165' AND EXISTS(SELECT 1…
-
1
votes1
answer143
viewsA: Take the lowest values of a Count using group by
You can use the clause WITH to reuse its query and bring only the greatest result of COUNT: WITH quantidade AS ( [SUA QUERY] ) SELECT q1.* FROM quantidade q1 WHERE NOT EXISTS(SELECT 1 FROM…
-
1
votes1
answer59
viewsA: How to add list to a Javascript object
Just initialize the field value values with a array empty and use function push to increase it. var object = new Object(); object.nome = "matheus"; object.produto = "caderno" object.values = [];…
javascriptanswered Sorack 27,430