Posts by Luiz Felipe • 32,886 points
746 posts
-
2
votes1
answer39
viewsA: Why specify a number of assertions explicitly in my test?
Yes, the idea is almost that same (I will explain at the end a remark on the statement of the question). In case, as you are testing an error, you can nay occur (due to some error), it is important…
-
2
votes1
answer44
viewsA: Pass generic form parameters through an array
Assuming vetorArgs be an array, you can use the scattering operator to "spread" the arguments to a function, which will accept a varied number of arguments - resource that called parameters Rest.…
javascriptanswered Luiz Felipe 32,886 -
5
votes2
answers237
viewsA: Access Javascript properties: point notation or square brackets?
There are two main (others as well, which do not fall within the scope of this answer) ways to access properties in an object. See more in "property accessors" in the documentation. The first of…
-
2
votes1
answer150
viewsA: Map Object Array and create new array from keys
There is nothing wrong with your solution, it is simple and clear. You may not use the map, once that method map one array in one another array. Thus, another option is to use the reduce. Something…
-
1
votes1
answer298
viewsA: How to return a tuple to a function in Haskell?
First, you don’t need to reinvent the wheel by creating a function tam, since, as in Haskell strings are lists of characters (Char), you can use the function length in a string, which will return…
-
1
votes1
answer97
viewsA: Is there any way to reuse a window with the target form?
The attribute target defines the browsing context of the action. In a form, this attribute will define the browsing context after submission of the form. As we already know, there are some special…
-
4
votes2
answers92
viewsA: What would be the function of this array?
Apart from the similar notation, this has nothing to do with array. In this case, the brackets denote a property advisor. Note, in your example, that you are creating an object through its literal…
javascriptanswered Luiz Felipe 32,886 -
3
votes1
answer2377
viewsA: Problem picking query params in URL by Express
It is necessary to understand the difference between a route parameter and a query string of route. Note in your code: app.get('/users/:id', (req, res) => { // ... }); The path you set in the…
-
0
votes1
answer128
viewsA: How to add a computed field with expression-based value in Mongodb?
What you want is to add one computed field, whose value will come from computing of existing values. You can use a resource called Aggregation Pipeline to do this, which has some stages (called…
-
8
votes1
answer93
viewsA: Functions with async / await running out of order
No, because the Promise implicitly returned by funcao2 is solved soon after the function is called (with a tiny delay due to the way these operations are stacked by JS). This makes the await do not…
-
3
votes2
answers39
viewsA: How do I display an Object type variable on the screen through Alert?
According to the documentation, the method Window.alert has an argument message, that: message is an optional string with the text you want to display in the dialog box, or an object to be converted…
javascriptanswered Luiz Felipe 32,886 -
4
votes1
answer74
viewsA: Type annotation in asynchronous functions in Typescript
It is not bad practice to write down the type explicitly when the type is any. Quite the contrary, it is a great practice to define explicit types when a cannot infer the type - as in this case. You…
-
5
votes1
answer66
viewsA: Renaming methods of imports?
How are you using the imports specified by Ecmascript 2015, you can rename them using notation as, thus: import { Foo } from 'foo-module'; typeof Foo; // "function", por exemplo. To: import { Foo as…
-
2
votes1
answer44
viewsA: How to convert Java source string to HEX for Unicode to embed in HTML?
You already have a map that creates a relationship between an icon name and its respective code escape for Unicode in Javascript, which will create an icon name map for a given character based on…
-
1
votes1
answer37
viewsA: Calling a function when another ends
As you are dealing with asynchronous processing, a good option for your case is to utilize callbacks. Just create two functions, making one of them receive one callback. Basically, you can do…
-
4
votes2
answers111
viewsA: How to make the browser render the <span> with some spaces in the text?
To be honest with you, there’s no point in you wanting to reinvent the wheel. If you simply want to display information in a tabulated form, the element <table> is ideal for what you need by…
-
3
votes1
answer57
viewsA: Does Settimeout run in parallel on Node.js?
Settimeout runs in parallel in Nodejs? No. In Javascript there is no parallelism. At least not until the introduction of Worker threads in Node.js or the Webworkers in the browser. There you can…
-
2
votes1
answer177
viewsA: Help with API/useEffect - React
The state is probably being changed yes. The problem is that you are running the console.log before it is changed. The status change process in React is asynchronous. Also, how are you working with…
-
1
votes1
answer42
viewsA: How do I use javascript to send Form data to an email address?
What you want to do is not possible on the client’s side. According to own documentation of the element <form>: The HTML element <form> represents a section of a document that contains…
-
6
votes1
answer74
viewsA: Optional dynamic keys Typescript
You can declare optional properties using the question sign: type Keys = 'a' | 'b' | 'c'; type MyInterface = { [key in Keys]?: string; }; Another option is to use the built-in type Partial<T>,…
typescriptanswered Luiz Felipe 32,886 -
3
votes1
answer30
viewsA: Empty space on top of page when creating a UL on the sidebar side
The problem is that in most user agent stylesheets, the element ul has a standard style that includes properties that define a margin standard. See, the default style in Chrome is this: ul { /* user…
-
3
votes3
answers199
viewsA: Cut unnecessary zeros from a string, without toFixed()
If your value is already in the string type, you can use a regular expression like this: /(^0+(?=\d))|(,?0+$)/g Which will remove all zeros at the end of a string and the comma if necessary. Behold:…
javascriptanswered Luiz Felipe 32,886 -
1
votes1
answer26
viewsA: Note task does not perform correctly
Note in the line below: return gulp.watch((caminho, ['scss'])) You are using the comma operator, which takes precedence over separating the arguments from the function since you are using a group of…
-
3
votes1
answer101
viewsQ: Are there advantages to using closures to maintain state rather than class?
It is very common to use classes to encapsulate state and some methods that modify it, such as this counter: class Counter { #val = 0; increment(step = 1) { this.#val += step; } retrieve() { return…
-
7
votes3
answers2304
viewsA: Check how many times a number appears in the array
Although it is possible to make your code work, I think it is worth understanding that there are other (simpler and more efficient) ways to do what you need. If you are always working with an array…
-
3
votes1
answer348
viewsA: Difference between constructor and function that returns literal object
In your first example, you have a function that works as a (constructor Function), which returns a new object instance if you call it using the operator new. Thus: function construtora(nome,…
-
1
votes1
answer45
viewsA: Selection of lines per keyword Vscode
Select the word you want to use as the basis (with the same cursor, without using the search tool). In your case it will be "title". Then press Ctrl + Shift + L to select all occurrences. Then press…
visual-studio-codeanswered Luiz Felipe 32,886 -
4
votes1
answer588
viewsA: How to start an object in Typescript without declaring all properties at once?
You can use the built-in type Partial<T>, which makes all properties of type T optional: interface Usuario { nome: string; senha: string; email: string; } function criarUsuario(nome: string,…
-
1
votes1
answer1123
viewsA: CSS - Remove focus from button by clicking
As you can see on Github, Bootstrap does not use outline to emphasize the state of :focus. He uses the box-shadow. Therefore, to remove, just disable this property. So: .btn-toggle { box-shadow:…
-
3
votes1
answer820
viewsA: Element has the type any implicitly when trying to access a property of a module namespace (object)
You are getting this error because, in Typescript, modules are also statically typed. So when you import all icons using the following notation: import * as Icons from 'react-icons/fa'; Typescript…
-
6
votes1
answer259
viewsQ: Creating regular expressions with a dynamic pattern is problematic? If so, is there a way to avoid the problem?
Let’s say, for some reason, I need to create a regular expression that has a part of its standard configurable by a user. Something like this very trivial example: const regex = new RegExp('^' +…
-
7
votes2
answers595
viewsA: How does toString work in Javascript?
The toString is a method available in several Javascript objects. It has a different behavior depending on the object it is part of. However, it always has the same goal, that is, to create a string…
-
2
votes1
answer345
viewsA: Nodejs - Async await with Mongoose
You are simply not using the await methods that return an interface Promise-like. Find out more about the await to actually know when to use it. In short, use it in methods that return a promise.…
-
2
votes2
answers96
viewsA: Assign jQuery function to variable in ternary operator
Your code at no time ceases to be effective by using if/else. You will lose readability if you want to stop using them in situations like this. But you can, yes, use a ternary operator. Simply…
-
3
votes2
answers283
viewsA: jwt.Decode - what is the need for a list of algorithms?
In the case of that particular library, according to the documentation: When Decoding, you can also specify which Algorithms you would like to Permit when validating the JWT by using the Algorithms…
-
4
votes1
answer85
viewsA: Difference when using an object and an array being passed as this no apply using the Concat function
Initial concepts First of all, it is important to know how to differentiate two concepts that are of paramount importance for understanding why your two examples above behave differently. Although…
-
2
votes2
answers40
viewsA: How to apply a function with "foreach", using a set of pre-selected items by the Jquery style selector?
If you want to create this without using classes, you can also use a more dependent approach Factory functions: There’s nothing wrong with classes. It’s just another example of using to show that…
-
2
votes2
answers459
viewsA: What’s the "Never" type for?
As stated in documentation: The guy never is a subtype and attributable to any other type. However, no type is subtype or attributable to it (except itself never). Up until any is not attributable…
-
4
votes3
answers775
viewsA: What are the ".d.ts" files?
The archives *.d.ts are called declaration files. The d in the name comes from declaration. The main utility is to declare types for applications or libraries originally made in Javascript. Thus,…
-
3
votes1
answer2567
viewsA: How to pass Information from a functional child component to a parent React?
First of all, it is worth remembering that JSX is nothing more than a syntactic sugar for Javascript. In this way, everything can still be represented as functions. So when you do: <Register…
-
2
votes1
answer119
viewsA: CSS: Shading of "triangle" created using ::after
You can use the filter drop-shadow, that unlike the property box-shadow, which creates a rectangular shadow behind the cashier of the element, creates a shadow behind the form of the object. Learn…
cssanswered Luiz Felipe 32,886 -
1
votes1
answer158
viewsA: Receive Nodejs post form returns Undefined
HTML forms do not send data in JSON format. They send us, by default, in Encoded URL format. Therefore, use middleware express.json() is, in your case, a error. You must use the middleware do the…
-
1
votes1
answer244
viewsA: How to copy an object array in Javascript?
One option is to use map, returning a new literal object in each iteration: function increaseAge(users) { return users.map((user) => ({ ...user, age: user.age + 1 })); } const users = [{name:…
-
3
votes1
answer31
viewsA: Object Null in DOM Manipulation
Any operation of query in the GIFT, such as querySelector may indeed return a Element or null, since there is no guarantee that the element will actually be on the page. There is the option to…
typescriptanswered Luiz Felipe 32,886 -
0
votes1
answer2287
viewsA: Unhandled Promise rejection typescript and Node.js
Express does not have a method for capturing bounces of promises natively. Therefore, how are you using async/await, should always ensure that no rejected promise "get out" from inside the router,…
-
6
votes1
answer657
viewsQ: What is and how does the "clamp" function work in CSS?
Recently I’ve seen some people talk about the function clamp. What is its real usefulness? Is there any relation to other functions, such as max or min?…
-
1
votes1
answer17
viewsA: Filter files of the same date ? JS
The method find will look for an array item that satisfies the condition you place inside the callback, returning the first element that satisfies it. To return a new array with all the elements…
-
0
votes1
answer97
viewsA: Turn function into String with Javascript
You can use the second argument from JSON.stringify, to pass a function of replace, that allows you to modify the way data is "serialized": const obj = { onload: () => console.log("Foo") }; const…
-
13
votes1
answer300
viewsQ: What is an asynchronous iterator in Javascript? What is its relation to "for await" loops?
What are asynchronous Javascript iterators? What is their function and what are the differences between the "conventional" iteration protocol? What is your relationship with for await .. of? It is…
-
1
votes1
answer54
viewsA: My inaccessible JSON key for Node.js validation
According to the knex documentation, you can pass an option as to rename the field count(data): .count('data', { as: 'data' }) From there the key of the objects returned to this field will be data,…