Posts by Luiz Felipe • 32,886 points
746 posts
-
1
votes3
answers95
viewsA: Pass Enum value per method parameter
There’s no way to do that. Because, if it were possible, you could do something like: Status.CANCELADA == 2L; // ??? And that should be evaluated for what? true? false? Like the Runtime would be…
-
7
votes1
answer126
viewsA: How to change the color when drawing a line segment that belongs to a circle?
You already have the answer to your question. If you know how to verify if a point belongs to the circle, just do the following check for each point of the straight you will paint: And your code…
-
11
votes2
answers224
viewsA: What is the underscore ( _ ) "inside" of a Javascript number?
It’s called Numeric separator or, in English, numerical separator. It was standardized in Ecmascript 2021. See repository with the proposal and discussions. And the section § 12.8.3 of…
-
3
votes1
answer43
viewsA: Show array first element that may not have been loaded using React
You are trying to render the elements even if they have not been loaded yet. As indicated in the comments, before of api.get Having been solved, the component is already being rendered as an empty…
-
15
votes2
answers399
viewsQ: How does Python structural matching (match declaration) work?
Recently, the Pattern matching structural version was introduced 3.10 (still in alpha) Python. For this, the keywords match and case. Were, in the notes of release, included several examples, among…
-
7
votes1
answer82
viewsA: Why doesn’t Github Workflow start?
This is what you get by copying and pasting. : P You’re saying explicitly to run this workflow only in the branch main: on: push: branches: [ main ] pull_request: branches: [ main ] This field…
-
3
votes1
answer169
viewsA: What is the difference between "test" and "spec" in automated testing?
There are semantic differences between naming a file as .test.ts and .spec.ts? Not formally. Jest does not convene any kind of "suffix" in the file name. It ends up being a convention adopted by…
-
3
votes1
answer179
viewsA: How to search for a substring from an offset in Rust?
I don’t know if this fits what you call "idiomatic," but let’s see... Basically, assuming we want to find the index of a substring from a given offset, we could do so: let string = "ABC ABC ABC";…
-
8
votes1
answer377
viewsA: How to leave an empty array (delete all elements) in Javascript?
Regardless of the values of an array, they are valid methods to empty an array arr: Alternative 1: Reset the variable (or property) to an empty array arr = []; This code will reset the variable arr…
-
2
votes1
answer52
viewsA: How to describe the execution of the loop for Javascript in Portuguese?
Keep in mind that the code itself is already the most suitable description you can have. Translating this code, in Javascript: for (let i = 1; i <= 3; i++) { let linha = ''; for (let j = 1; j…
-
2
votes1
answer39
viewsA: Should reducing functions be created outside or inside my React component?
Is there any advantage/disadvantage in using the reductive function outside of the component statement in comparison to using within the component? Yes. It is more advantageous to declare them…
-
2
votes1
answer48
viewsA: How to pick up specific columns in JS Object
With the exception of the table header (the first "row"), numerical values are placed in columns two and three (indexed as 1 and 2, respectively). So, just iterate over all the rows and their…
-
3
votes5
answers120
viewsA: Merging an array with an object array
An option would be to iterate over each element of applications and, for each iteration, search in the array apis, the object api correspondent: function groupApplicationApi(applications, apis) { //…
-
2
votes0
answers69
viewsQ: Are there advantages or disadvantages between using closures or classes to achieve Javascript dependency injection?
Let’s say I have a function that depends on a logger to work. To follow the "good practice" and achieve a certain level of decoupling, I decide to make use of dependency injection so that this…
-
2
votes1
answer166
viewsA: Change background color when typing a color via v-bind
Notice that you are building a new instance of Vue: new Vue({ el: '#app', data: { myClass: '', } }); Note that the variable myClass is started as an empty string. Now note in your template the…
-
4
votes2
answers107
viewsA: Using do/while in Javascript to request 10 numbers from the user
The code seems reasonable to me (for someone I think is starting out), although there are some problems: You’re not asking for 10 numbers, but 12 It can be observed that in the condition num <=…
-
1
votes1
answer52
viewsA: Doubt about creating event maps - Typescript
The callback of map does not return an array of IEvent, but rather a IEvent. Change the return note from callback of IEvent[] for IEvent. The array type IEvent[] is returned by whole the map, so…
-
7
votes2
answers155
viewsA: Is there any way to prevent the use of "new" in a Javascript function?
An alternative is to use the syntactic construction new.target, refers to the constructor function when the function is called using the operator new. Thus, if new.target is defined, it is inferred…
-
6
votes2
answers155
viewsQ: Is there any way to prevent the use of "new" in a Javascript function?
Assuming the function: function foo() { return 'something'; } It is possible to invoke it (abstract operation [[Call]]): // Invocando `foo`: foo(); In the above example, the string would be returned…
-
1
votes1
answer263
viewsA: Nextjs with Typescript and Styled-Components not working
You must use the naming convention PascalCase to name "own" components (created by you, the programmer). When this convention is not properly followed, the Typescript compiler understands that you…
-
2
votes1
answer96
viewsA: How to sort a list of user-provided words using Python?
The problem is that when you pass a string to the constructor list, all characters in the string will be converted to individual elements of the list. You then need to pick up the string (with the…
-
2
votes1
answer53
viewsA: How to create a Union type from the elements of an array type in Typescript?
You can get a union with all array types using bracket notation. So: type MyArr = [1, 2, 3, 4, 5]; // %inferred-type: 5 | 1 | 2 | 3 | 4 type MyArrUnion = MyArr[number]; See on Typescript playground.…
-
2
votes1
answer302
viewsA: Check that the string only contains Python letter and space
The error happens because the method str.isalpha checks whether all the characters in the string are composed of letters - "alphabetic", according to the documentation puts. One option is to…
-
0
votes1
answer68
viewsA: AJAX request failed to use the file:/// protocol at source. How to resolve?
You are trying to make an XHR request (or Fetch, in terms modern). Other people may understand how to request AJAX. In summary, CORS is: CORS (Cross-Origin Resource Sharing) is a system consisting…
-
12
votes2
answers455
viewsA: What is the new Javascript Temporal object?
The Temporal API is, at the time of writing this response, a proposed addition to Ecmascript that is at stage 3 of the process of incorporation into the specification (the infamous TC39 process).…
-
14
votes1
answer313
viewsQ: What are the precautions to be taken when using top-level await in Javascript?
To proposal for the top-level await has just been completed, which means that this feature will soon be part of the language. As far as I know, this feature will only be available when executed in…
-
3
votes2
answers84
viewsA: Filter object array from a Javascript search string
Note that when the string is in a pattern like foo#bar and you divide it by the character #, returns an array as: ['foo', 'bar'] But when the string is in a pattern like #bar and you divide it by…
-
6
votes2
answers570
viewsA: What is the difference between Object.create or new Object() in Javascript?
TL;DR In the great majority sometimes, to create an object in Javascript, just do something like this: const myObject = { // ... }; So, a new object will have been created myObject whose prototype…
-
0
votes0
answers36
viewsQ: Is it possible to see the "optimized" version of Javascript running from the browser?
I recently started to study compilers and learned that, in an intermediate phase of the whole process, there may be a number of parsing passages aimed at improving the performance of the code (in…
-
5
votes3
answers90
viewsA: Group array of emails by domain of each email in Javascript
An option is to iterate over each element of the original array, divide the element (which is a string) by the character @ and insert in a dictionary of arrays according to the domain. Note that it…
-
6
votes1
answer79
viewsA: How to pass a dictionary to the range() function
This happens because the function range is not implemented directly in Python, but rather in C. In this case, the C function has been developed to accept only the arguments in positional form.…
-
3
votes1
answer27
viewsA: Error using the 'is' method
You are trying to use the method is jQuery on a native browser interface. Like this native interface nay implements the method is, you receive an error when trying to invoke something that is not a…
-
3
votes3
answers45
viewsA: Problems centering content when working with flexbox in CSS
The elements are centered on both the X and Y axis of the flex container. See, when you do: .elements-container { display: flex; align-items: center; justify-content: center; flex-direction: column;…
-
2
votes2
answers68
viewsA: Move element up in 50% of its size
You can use the CSS property transform for move the element up by 50% of its size. For this, use the transformer translateY, that move the element on axis Y. So: transform: translateY(-50%); So…
-
1
votes1
answer40
viewsA: How to recover variable value (custom Property) CSS?
There is no reason to use jQuery for this! : -) You can use the method getPropertyValue, available in prototype type objects CSSStyleDeclaration. A simple example: // Equivalente ao pseudo-seletor…
-
3
votes3
answers63
viewsA: How NOT to separate a number of two or more digits when adding to a Python list?
As an alternative to the other answer, I would give to do this relatively simply using a regular expression: import re nums = re.findall(r"\d+", "A2B4C13") print(nums) # ['2', '4', '13'] See working…
-
3
votes5
answers15150
viewsA: How to avoid "Cannot read Property ... of Undefined" error?
The TypeError message "Cannot read Property ... of Undefined" is launched when trying to access a property at some value of the type undefined or null. The other answers to this question indicate…
-
5
votes1
answer93
viewsA: What are the main types accepted by the Fetch API for the HTTP request body?
The estate body is responsible for defining the body of the request to be made by fetch. The type of data you can pass to this property is varied, so it accepts: FormData URLSearchParams USVString…
-
6
votes1
answer93
viewsQ: What are the main types accepted by the Fetch API for the HTTP request body?
I know I can use the API fetch to perform HTTP requests by browser. And I know I can use the property body to configure the body of the request. But I would like to better understand which types I…
-
10
votes1
answer215
viewsA: What is IEEE 754?
Numerical representations - fixed and floating There are two main ways to represent real numbers in binary: Fixed point (Fixed point) Floating point (floating point) In summary, fixed points are…
terminologyanswered Luiz Felipe 32,886 -
6
votes1
answer95
viewsA: When a calculation is made in C#, is the primitive type of the variable maintained in the result?
In the case of division into C#, the compiler will base the type of evaluation on the type of operands. If all the operands in the division have an integer type, then the operator / will return as a…
-
1
votes1
answer36
viewsA: How to check the type of a unit test value using Jest?
If you want to test the type of some value in Javascript, nothing prevents you from making an assertive using the operator typeof. So, for example, to check if any value <value> is numerical…
-
5
votes5
answers287
viewsA: How to go through an array of objects, add specific properties and unify those objects where it has a specific property equal to another?
You can accumulate each nome single and go adding the preco of each object by nome corresponding. Once the map has been completed, the new array is generated. One way to keep objects from a single…
javascriptanswered Luiz Felipe 32,886 -
0
votes1
answer65
viewsA: How I remove the String from inside a Sequelize return
Note that you have an array and want map each element of the original array in something else. This will then generate an array of the same length as the original. In this type of situation, the…
-
3
votes1
answer67
viewsA: Doubt about the reduce method in Javascript
We must understand, first, that the Array.prototype.reduce works on an array. In this case, the array that will be reduced is the array itself under which we call the method reduce. Beyond the array…
-
1
votes1
answer289
viewsA: How to multiply all elements of an array by number in Python?
On line 5 of the code, when you do: resultado = resultado + (elemento * n) You are trying to use the operator + between two operands of different types. The resultado (first operand) is a list and…
-
3
votes1
answer104
viewsA: How to Force Prettier to Always Put a Multilevel Ternary
You can be mixing things up. Prettier is a formatter extremely opinionated code, so it has very few configurations concerning the formatting of the code. More details. This way, you have to choose…
-
9
votes1
answer74
viewsA: A function created within another function is created with each call or persisted by reference?
First of all, one needs to understand the fact that whenever a function is called, the block it defines runs. A function (by itself) cannot maintain state between two or more different calls. Note…
-
4
votes1
answer207
viewsA: How to render the same component several times in React?
How an React component is nothing more than a mere call to React.createElement, is the same thing as creating an array with N elements. A simple example: create an array with 5 booleans true: const…
-
3
votes1
answer111
viewsA: How to return the value of a function that uses Javascript promises?
As I said in this another answer, Javascript has an intrinsically asynchronous nature. Moreover, once a function works with some asynchronous operation, the caller of function accurate to suit the…