Posts by Luiz Felipe • 32,886 points
746 posts
-
7
votes3
answers204
viewsA: How to serialize and deserialize objects containing Bigint values in Javascript?
There is no "standard" way to do this serialization. The most trivial way around this problem is to use the second argument from JSON.stringify, which receives a function to modify the way the data…
-
4
votes3
answers2823
viewsA: How to add and remove classes with Javascript?
There is the API classList, which is basically a DOMTokenList containing all classes of a given element. The estate classList can be accessed in objects that implement Element. First you get the…
-
6
votes1
answer75
viewsA: Check that all sub-rray items are in "false" status
The method Array.prototype.every checks whether all elements of an array satisfy a predicate. See the example: const arr1 = [11, 12, 13, 14, 15]; const test1 = arr1.every((num) => num > 10);…
-
5
votes1
answer35
viewsA: Comparing captured keyboard strings to Rust
The method read_line, that you are using to read the user input from stdin, reads the input until you find a line break - usually represented by \n. Note in this example that the modified string…
-
8
votes3
answers126
viewsA: Why does type "any" exist in Typescript?
To understand the motivation of any, it is necessary, rather, to understand one of the fundamental principles of Typescript, which is to enable gradual adoption. For a long time, the Javascript…
-
5
votes3
answers109
viewsA: How to compare arrays ignoring the order of the elements in Jest?
Compare already ordered arrays The most obvious alternative is to use the sort to make arrays be compared in the same order. In this case, order by property name: const sortByName = (os) =>…
-
5
votes3
answers153
viewsA: What is the way to check and react to a change of state of an array using pure Javascript?
A simpler alternative is to use a subclass that does nothing but execute any code - in this case some logs - and delegate to the original implementation of the superclass. Is trivial: class…
-
5
votes1
answer84
viewsA: Why, when not using "this", the method does not reflect changes made to the object?
Actually, updates the object yes. See: class Endereco { constructor(rua, cidade) { this.rua = rua; this.cidade = cidade; this.exibirEndereco = function() { console.log(`Endereço: ${rua},…
-
3
votes1
answer22
viewsA: Regex to get result from above line
The problem with its regular expression is that the character set [A-Za-z0-9\s] does not contain the character -. Then the regular expression ends up in the next hyphen 1505 . The problem is, by…
regexanswered Luiz Felipe 32,886 -
2
votes2
answers71
viewsA: How to extract substring in string array with Javascript using match?
The result you reported is expected, see: I have tried to convert to simple array and use the String.match() JS with the regexp <(.*)>, but the return is another array and with other data that…
-
1
votes1
answer48
viewsA: How to append a JSX component inside an item from . map()
I would say that a more interesting alternative is to extract the part of the code that corresponds to list item for its own component. So instead of a single component, responsible for the list and…
-
2
votes1
answer65
viewsA: What is "Error cause" in Javascript?
The proposal Error Cause is basically an extension to native language error constructs to allow the addition of contextual information to the error to be instantiated. This information is a mere…
javascriptanswered Luiz Felipe 32,886 -
5
votes1
answer70
viewsA: Doubt about C++ pointers
It happens because when you do: std::string somebody = "Luiz"; char* pointer = &somebody[1]; You declare pointer as a pointer to a character. Do you know what a C string is? It’s basically an…
-
2
votes1
answer40
viewsA: Is it possible to customize the native browser permissions dialog?
There is no way to do this. This decision is intentional and extremely important for the safety of users. Browsers are programs that execute arbitrary code on the user’s computer. And, depending on…
-
2
votes1
answer43
viewsA: How to give the same answer to different possible user entries
You cannot use the equality comparator (==) to check if a list contains a certain element. In this case, you are comparing the list with a value that is not even of the list type. This will always…
pythonanswered Luiz Felipe 32,886 -
7
votes2
answers80
viewsA: How to understand mapping (map) of functions list in Python?
Until now I had only seen list of values in this argument. There is no difference because, in a way, a list of functions is still a list of values. The logic is the same, let’s recap. The more…
-
3
votes2
answers71
viewsA: Is it possible to overload Javascript mathematical operators for objects?
Operator overload exists in Javascript? What the question asks does not exist in Javascript. It is called Perator overloading, or, in Portuguese, overload of operators. The behavior of Javascript…
-
7
votes1
answer49
viewsA: Does the <Section> tag replace the <main>?
From a semantic point of view, no. The tags <main> and <section> have different meanings for HTML5, which is based on ideas of semantic structure. According to the documentation,…
-
3
votes1
answer30
viewsA: VS Code does not recognize methods of the Event object
Even Typescript would not help in this kind of situation. There is a lack of information required for "inference" of types. The problem is that the compiler (used internally by Vscode) does not have…
-
2
votes3
answers321
viewsA: Function to calculate the distance between two points
Just to complement the answer that already explains some points in relation to the original code, it is possible to shorten even further the part of the calculation of the distance itself. This is…
javascriptanswered Luiz Felipe 32,886 -
7
votes2
answers86
viewsA: Is there a difference in creating objects and adding properties with literal notation or with`new Object` in Javascript?
There is no difference in relation to building object, but the semantics of how properties are added is different. Literal objects in Javascript are syntactic sugar for building objects Object.…
-
3
votes2
answers84
viewsQ: Is there a difference between "accuracy" and "precision" in computing contexts?
Recently, appeared on the site a question which deals with "inaccuracy" of the value returned by the method Math.toRadians Java. However, in other places (such as in the answers of this question),…
-
4
votes1
answer123
viewsA: What is the difference between the rest operator (%) in Python and Rust?
The basic premise is that although the symbol is the same, the meaning may be different. Operator Parlance Semantics % Rust Remainder % Python Modulus This difference occurs among several other…
-
4
votes1
answer56
viewsQ: What are the differences between Traits (or Typeclasses) and Interfaces?
Studying Rust, I began to make use of the so-called traits that, according to the language book: We can use traits to define shared behavior in an abstract way. The same chapter further quotes the…
-
3
votes2
answers144
viewsA: What are the differences between constants declared with const and immutable variables declared with Let in Rust?
The keyword const defines a constant. On the other hand, let defines a variable. About the place where the declaration occurs, constants can be declared in any scope, including the top-level…
-
4
votes2
answers64
viewsA: Is it possible to perform an overload (Overload) with Arrow functions?
You will not be able to use the syntax "similar" to that of function statements since Typescript does not understand that multiple function statements via Arrow functions defined with const (or even…
-
2
votes1
answer36
viewsA: Is React able to automatically remove eventListeners from Refs when the component is destroyed?
No. React is not able to determine that you have even created a Event Listener within a useEffect. In this type of case, what you need to do is use a returned function of the callback of useEffect…
-
2
votes1
answer65
viewsQ: What is it and why should I provide a "dependency array" for React’s Hooks?
Who has never forgotten to pass a "dependency" to the dependency array Hooks react? It’s an unfortunate burden that every person using React has to be aware of: passing the right dependency to the…
-
1
votes0
answers24
viewsQ: How does it work and what are the implementing context rules for Ecmascript 6 modules (ESM)?
Since Ecmascript 5, Javascript has traditionally had two execution contexts: Sloopy mode (informal name used to refer mode enabled by default in most execution contexts). Strict mode, explicitly…
-
4
votes2
answers57
viewsA: What is the difference between onDestroy and the function returned by onMount callback in Svelte?
Callback of destruction via onMount The life cycle function onMount agenda one callback to be executed once the component has been assembled in the FOD. Optionally, if this callback return another…
-
4
votes2
answers52
viewsA: How to allow the click event to be ignored by clicking inside an element?
The estate event.target refers, in the case of click events, to the element that issued the event in question. Knowing this, you can use the property target to verify that the element that activated…
-
5
votes1
answer81
viewsA: What is list comprehension? Control structure? Loop?
List understandings are nothing more than a syntactic sugar for the construction of lists, often from another list or through some well-defined rule. These constructions were inspired by notation…
-
5
votes2
answers48
viewsA: What is the difference between using forwardRef or another prop to pass the reference?
The difference is that when you use the name ref, is adhering to a convention already established in the community. Therefore, if a component you develop will require, from those who consume it, a…
reactanswered Luiz Felipe 32,886 -
2
votes2
answers189
viewsA: How to calculate the distance in fewer lines?
Only to complement the another answer, you can use the function hypot, defined (also) in the header math.h. View documentation. This function basically returns the square root of the sum of the…
-
5
votes1
answer102
viewsA: How to request user input in Node.js?
Unlike browsers, exposing a function in the global object called prompt, Node.js does not implement it. To request a user input, you can use the module readline, from Node.js. See an example: const…
-
1
votes2
answers46
viewsA: How to iterate over a string by obtaining the indices of each character in C++?
The enumerate is required in Python since the language does not have the for "traditional", where the programmer creates a counter variable (usually i) and increases it with each iteration. Because…
-
3
votes2
answers127
viewsA: How to detect Start Codon and Stop Codon in a nucleotide sequence using Python?
The code works, so that will carry out the count from the codon ATG up to the TAA. The problem is there are three stop codons and the program only recognizes the TAA. See, the problem is where you…
-
2
votes1
answer31
viewsA: Body of the request (req.body) returning empty object when submitting form
Are you using the middleware incorrect. HTML forms, that is, the elements <form>, by default send the data submitted by the user in the body of the request with the Content-Type…
-
3
votes1
answer40
viewsA: How to set a plugin settings next to Next.js settings?
You really can’t have two module.exports, since each Commonjs module may have only one entry point (denoted by exports). Usually the configuration of plugins of Next.js accepts nesting of functions…
-
4
votes2
answers46
viewsA: Enum initialization
By default, the associated value of enumeration member constants is of the type int. The first variation starts at zero and is incremented by one for each following variant. Therefore, in this…
-
1
votes1
answer55
viewsA: How to create a type from a variable in Typescript?
At type level, the operator typeof returns the type (if present) of its operand value. For example: const foo = "FOO_STRING"; type Derived = typeof foo; // tipo inferido é: "FOO_STRING" See more on…
-
4
votes0
answers40
viewsQ: What are parser combinators?
Recently, studying on techniques of Parsing, found out about parser combinators, which seems to be a more functional approach to realize the parse of a sequence of characters. What is a parser…
-
1
votes1
answer49
viewsA: How to apply a CSS style only to devices that do not have a mouse?
The media Feature pointer allows you to make a query to determine which type of cursor the user’s device has. According to the documentation, three test values are possible: Test value Description…
-
5
votes1
answer77
viewsA: Why does the Math.toRadians method return an inaccurate value?
How you convert an angle in degree unit to radian? To formula usual is in the question itself. Given an angle x of degrees, is determined its α in radian by: α = x * π / 180. Let’s see, for example,…
-
5
votes2
answers116
viewsA: How to get the only different value inside an array in Javascript?
I think you’re complicating a lot by using the Array.prototype.map there. You don’t actually need to map the array to solve this problem. It looks like you’re using the Array.prototype.map as a…
-
2
votes2
answers73
viewsA: Is there documentation in the Ecmascript standard that ensures that an array when passed as a property advisor has a defined format?
In Javascript, objects are collections of properties. However, an important constraint occurs for keys of these properties. For design, the language chose to allow only keys of the type string or…
-
3
votes1
answer74
viewsA: Are "Empty" values within an array not eternal?
Congratulations, you just discovered the bumpy arrays in Javascript! When you create an array and assign it a value in an index beyond its limits, it will "punch" the array. For example: let arr =…
-
4
votes2
answers47
viewsA: Is it possible to discriminate unstructured values of an object with union type in Typescript?
In short, it is not possible to do the de-structuring before the branching and also carry out discrimination of union types. Notice that when you do the de-structuring before the branching (in that…
-
5
votes1
answer60
viewsA: What is the relation of the "+" operator to the "valueOf()" method in Javascript?
This is a behavior that is due to the nature of coercion typical of Javascript. It is a language that historically relies on automatic type conversion, so there are several mechanisms for this to be…
-
3
votes1
answer51
viewsA: Is there a way to specify a hash, version, or signature when running `npx` (from npm)?
There is the possibility to provide a specific version of the package to be installed by npx. Of documentation, you can use it like this: npx [options] <command>[@version] [command-arg]... As…