Posts by Luiz Felipe • 32,886 points
746 posts
-
0
votes2
answers306
viewsA: Error exporting footer in Reactjs
Note in your file Footer.js that you are exporting the component as default: export default class Footer extends React.Component { /* ... */ } // ↑↑↑↑↑↑↑ // Notação de um default export And in the…
-
2
votes3
answers92
viewsA: Optimize adding events to various Javascript elements
In relation to listeners event, you can create a array with numbers and get the Ids through a forEach. Something like that: [1, 2, 3, 4].forEach((num) => {…
javascriptanswered Luiz Felipe 32,886 -
2
votes1
answer428
viewsA: Typescript error when rendering a component that returns array in React
Basically, it’s a Typescript error. As you can see in the React documentation, there is nothing wrong with rendering a component that returns an array of elements (depending on its components Repos…
-
1
votes1
answer49
viewsA: Web Scrapping Nodejs - I cannot use variable as parameter
After a little research, I found this document. In accordance with I pondered on the comments, the method evaluate really does a certain magic behind the scenes, which causes all this confusion.…
-
8
votes1
answer333
viewsA: Is it possible to run a Javascript code after page forwarding?
It is impossible, at least through current browsers, to execute scripts on a page to which the user will be redirected. At least it’s meant to be, since they may exist flaws or unknown malicious…
-
4
votes1
answer25
viewsA: Get values for the javascript-clicked div
When you define an attribute onclick in some HTML element and calls a function by passing the this as argument, you will receive the element instance. So, how this instance you receive as a…
javascriptanswered Luiz Felipe 32,886 -
18
votes2
answers303
viewsA: What are computed names ("dynamic" structuring) in Javascript?
Basically, it is a facilitator to access properties dynamically within a breakdown. What is a breakdown? First, it is worth mentioning what is the structuring of objects in Javascript. For this,…
-
4
votes3
answers108
viewsA: How to replace a string depending on page resolution
You must create a Istener resize to "know" whenever the window has its size changed. Something like this: function setText() { const element = document.querySelector('#el'); // Você pode usar media…
-
2
votes1
answer195
viewsA: Difference between exporting a function and an IIFE in Javascript
Nothing changes in the "module import and export context". What will really change, between the two examples, is the value which will be exported. In the first example: module.exports = (function()…
-
8
votes3
answers179
viewsQ: Two different parameters that an accepted function can classify as having O(n²) complexity?
Let’s say I define a function as follows, which accepts an argument a be a array two-dimensional numbers: function totalSum(a) { let total = 0; for (const elem of a) { for (const subElem of elem) {…
-
13
votes4
answers985
viewsA: Compare string with array to return the most compatible item
The problem is that you need to split each element of arr in a word array. For example: ["frase qualquer", "uma qualquer aqui", "nada compatível"] It has to be turned into: [ ["frase", "qualquer"],…
-
6
votes1
answer109
viewsA: Doubt about generic types in Typescript
The problem you are facing boils down to: the generic never is a value, but rather a type. That way, you cannot use it as a value. See, in your code, you’re doing this: return await…
-
4
votes3
answers379
viewsA: How to take a value among many keys, but ignoring the keys, except the most internal?
You can use the following regular expression: /^{+({.*?})}+$/ Basically, it will give match in a string as follows: ^{+ Start with one or more characters {; ( We set up a capture group: { Have a…
regexanswered Luiz Felipe 32,886 -
6
votes2
answers928
viewsA: How to hide Axios request data in Javascript (JS Node)
It is impossible to hide HTML, CSS or Javascript from the client. The most you can do is use minification tools (as suggested by @Costamilam) or obfuscation. Even so, if the code is in the client,…
-
9
votes3
answers1939
viewsA: Separate integer and decimal part into a number using Javascript
You can transform the number into a string and separate the whole part of the decimal part using the split, a string method in Javascript. Something like that: const num = 46.5; // Convertemos o…
javascriptanswered Luiz Felipe 32,886 -
1
votes2
answers403
viewsA: How to return the years array using React-select
You can also opt for a slightly more declarative solution without the need to use an imperative solution. There is nothing wrong with the for, but he’s a little shy of the "unchanging" standards…
-
3
votes1
answer77
viewsA: How do the methods used within classes work?
This kind of "building" is a method, but in some cases are also referred to as macros. So when do we: class MyClass some_method() end The method some_method is being executed at the time when…
rubyanswered Luiz Felipe 32,886 -
4
votes1
answer77
viewsQ: How do the methods used within classes work?
It is very common in Ruby to use methods within classes, such as attr_accessor, or even libraries, such as validates_presence_of, ruby on Rails. I would like to create: class Person add_name_getter…
rubyasked Luiz Felipe 32,886 -
1
votes1
answer58
viewsA: React - Build too big
Often when you don’t do the optimization itself, the size of the build can grow quite large once all the files you are importing are placed in the same output, including its dependencies. There are,…
-
1
votes1
answer329
viewsA: Time formatting problem when using Moment.js and Dialogflow
According to the documentation on Moment.js formatting, the tokens HH and mm format, respectively, for the hour in 24 hours (between 00 and 23) and the minute (between 00 and 59). So, if you want to…
-
3
votes1
answer46
viewsA: Proptypes always gives error no matter if the value is correct
Although, in Javascript, the type of an array is object, Proptypes does not consider an array as an object. Demonstration: console.log(typeof {}); console.log(typeof []); In your case, it looks like…
-
12
votes1
answer5238
viewsA: How to disable compressed folders in Vscode?
As stated in Notes to the new version (1.41), November 2019, this resource can be controlled through the option explorer.compactFolders. To disable these "line folders" or "compressed folders",…
visual-studio-codeanswered Luiz Felipe 32,886 -
2
votes2
answers79
viewsA: Convert date from yyyyymmdd to dd/mm/yyyy
If the date is always in format YYYYMMDD, you can use a regular expression to do the match of each individual part of the date. Something like that: function parseDate(dateString) { const [, year,…
javascriptanswered Luiz Felipe 32,886 -
15
votes1
answer433
viewsQ: What are logical properties in CSS?
Recently I found the concept of "logical properties in CSS". It seems to me, is a new system to create CSS in a logical way, not physical (direction and fixed positions, let’s say so). However, this…
-
6
votes0
answers164
viewsQ: How to handle "large iterations" using recursion?
In the context of functional programming, it is said that any type of loop repeats (such as for or while) should be set aside in favor of recursion. But as the number of elements of the work begins…
-
3
votes1
answer109
viewsA: How to use await instead of . then() in Javascript?
The console is logging in undefined because the function delay returns nothing (what is undefined). For example: function test() { // Não retorna nada. } console.log(test()); // undefined If you…
-
1
votes1
answer609
viewsA: ERROR 1045 (28000) MYSQL
The problem is that you are probably not passing the correct "login" credentials, that is, the username and password. The default user is root. Then you can try: mysql -u root -p The flag -u…
-
6
votes1
answer404
viewsQ: How does type "Unknown" work in Typescript?
The guy unknown is a Feature a little more recent language, and is said as a any, only that type safe. So I was left with some doubts: What is your difference from any? It is safe to use it for type…
-
1
votes3
answers1566
viewsA: Why doesn’t Node.js run sucrase - a locally installed package?
You can use the commands npm run or yarn run to run any binary that has been installed locally. This means that you can run "Clis" provided by packages without the prefix ./node_modules/.bin. For…
-
4
votes2
answers108
viewsA: Async Await / Promise / API Google JS Node Translator
You need to create a Promise explicitly. You have already researched the basic workings of a promise? Basically, all Promise works like this: const myPromise = new Promise((resolve, reject) => {…
-
2
votes1
answer237
viewsA: Crawler
As placed by Guilherme Nascimento in the comments, you can develop a Crawler in Javascript using Node.js. There are even libraries that help you, through a headless browser (no visual interface,…
-
0
votes2
answers46
viewsA: I’m not passing any data on the request but it seems that some information is coming
Only with the code snippet below is it possible to understand where your mistake came from: const {location} = req.query const {characteristics} = req.query let spots if ({location}) { /** ... */ }…
-
6
votes1
answer64
viewsA: How to pass as two array as argument in a function?
Cannot return two values in a function. Each return that you give only returns one value. Thus, if you want to return more than one value for a function, you must use a fixed-size array. In…
javascriptanswered Luiz Felipe 32,886 -
3
votes1
answer90
viewsA: How to decrease decimal places with EJS
EJS interprets expressions in Javascript. This way, you just need to use some global object rounding method Math. To round up, use Math.round; To round up, use Math.ceil; To round down, use…
-
4
votes1
answer339
viewsA: Does the Eslint option of "enforce code style" add any behavior when we are already using Prettier?
It is not really necessary, since Prettier is already responsible for formatting the code, that is, making changes to the "style" of the code. Such as, for example: Semicolon (optional in most…
-
3
votes1
answer41
viewsA: How to define the possible values of a string in an iterface from an object?
You can use the keyof, that returns a Union type of strings containing all object keys. Then you’d have something like: interface ConfItem<TypeItem> { titulo: keyof TypeItem } See the example…
-
2
votes1
answer149
viewsA: Node js loop Time
You can create a function wait, that returns a promise that will be resolved after a certain time. Something like that: function wait(time = 0) { return new Promise((resolve) => {…
-
2
votes2
answers327
viewsA: Javascript run one click at a time
You can use the attribute disabled to check whether the button has been clicked or not inside the Handler of the event. Something like this: $('#btn').on('click', function() {…
-
1
votes1
answer55
viewsA: How to use multiple languages
You can use the Promise.all, that solves a list of promises simultaneously. Thus, a final promise will be returned as soon as all those passed are resolved. An example: // Nossa função que retorna…
-
2
votes2
answers81
viewsQ: What is it, Farmhash?
I recently discovered the FarmHash. Apparently, it is an implementation to hash some data. I was left with some doubts: It behaves in the same way as the most common hashes, such as md5 or sha? What…
hashasked Luiz Felipe 32,886 -
2
votes4
answers330
viewsA: Create "dark" function on the site!
You can use cookies or the API of localStorage. In that answer, I will demonstrate how to use the localStorage to persist data through front-end. const lightButton =…
-
1
votes2
answers347
viewsA: Use Axios to generate an unordered list using the Github API
According to the Github API, the repository name can be obtained from the property name. The problem you are experiencing is caused in the following section: for (var item in repos) { var textItem =…
-
0
votes1
answer82
viewsA: Activate the click event with a class
You can use something called Event delegation to make it work. Just add the Listener of the event click to a relative of the elements: $('.tarefas').on('click', '.titulo-ef', function() {…
-
2
votes2
answers85
viewsA: How to create a property in a Javascript method
One could say that the prototype is the "predecessor of classes" for Javascript object orientation. However, it is worth emphasizing that the classes that were implemented in Ecmascript 2015 are…
-
6
votes2
answers623
viewsA: How to publish a Typescript library on NPM?
The error you are having when importing the module by Typescript: Cannot find module 'idb2promise'. ts(2307) It is noted that Typescript is trying to solve the module using the new module…
-
1
votes1
answer61
viewsA: Question about ES6 import/export
The syntax { token } of a import is not to dismantling of an object. Therefore, you must export the value token thus: export const token = 'example'; And import it so: import { token } from…
-
2
votes1
answer46
viewsA: Does anyone know why the list remains empty even after await (Node.js)?
The method mysql.query probably not a Promise, then use the await it won’t do any good. You must deal with the value data within the callback, given the asynchronous nature of Javascript. When you…
-
3
votes2
answers149
viewsA: File deletion with Fs not working
You are using an asynchronous method (fs.unlink), waiting for a callback for when it is solved. Thus, you should use a function of callback to see if there were any mistakes: if (results[0].photo…
-
4
votes2
answers256
viewsA: How to get checkbox value unchecked using JS?
Just use the property checked, for example: const input = document.querySelector('input'); document.querySelector('button').addEventListener('click', () => { // A propriedade `checked` retorna um…
-
3
votes1
answer69
viewsA: How to manipulate an empty filter?
You should already know this, but when the filtering function passed to filter returns false, the iteration element in question is simply removed from the list. Thus, if none of the items passes the…