I have to multiply the sign of all elements in an array. For example 1: Ex2: Ex3: And here is my solution However, the output of ex3 cal([1, -2, 3, 0]) is -0. I’ve already thought about adding one more condition like this And obviously, It looks ugly. Is there a more elegant way to resolve that? Answer …
Tag: javascript
Suggestion to refactor code into simple way -React
I have multiple with the same class name and method with different parameter i want to refactor the below code to a simpler way any suggestion would be helpful. I want to refactor the code with the same component. Answer I hope this would be helpful. thanks
mapping the data does not work for me react js/axios
I deleted the map in the return because it doesn’t work. I get a error like: map is not a function. I hope someone can help me.. This is the code: This is the response from the console.log: {“data”:{“proposals”:[{“id”:”0xc1d3a777729a2f595be7723b22f406b9bba68d4cf…
Open one accordion section at a time. (Svelte)
I’d like to ask someone who can figure out how to allow this accordion component to open only one section at a time. It means that if a new accordion is open the previous one has to close automatically. In the ideal situation, this function could be optional for specific accordions. Thank you for your t…
Postman Pre-Request Script to Read Variables from CSV file and Append to JSON Body
I have a JSON body with template to pass to an API endpoint in Postman/Newman as follows: Everything enclosed in double braces is a variable that needs to read from an external CSV file, which looks like: Note that the CSV isn’t necessarily 2 entries long – I’d ideally like it to take in a d…
Javascript Improve collapsing element
I have created this toggle script which works well but I need to improve it so that onclick, any previously collapsed (i.e. open) subcats would simultaneously close and only the one clicked should collapse (i.e. open). Answer First, loop through the open elements and remove the class and set max height to nul…
Javascipt to count increment price for each tier
I am new to coding and currently touch the javascript part. I am facing a question about how to calculate the different tier prices and charges as shown in the image: Tier Pricing Table This is the code that I have tried. i represents the LOAN AMOUNT tier. When i is equal to 1 it will use the next tier
Make table which have cells 10×10 and every cells have inside number from 1 to 100
Need to make table which have numbers from 1 to 100, and it should be 10×10 cells. I make cells 10×10 but result fill every grid line from 1 to 10, how to make every line like that 1 to 10, 11 to 20 and to 100 like that ? Thank you for attention to my problem. Answer
Shorten text after 50 characters but only after the current word
I need to shorten text after 50 characters but if the 50th char is at the middle of a word – cut only after the word and not before. example text: Contrary to popular belief, Lorem Ipsum is not simply text (59 chars) expected output: Contrary to popular belief, Lorem Ipsum is not simply (54 chars) I was…
How to make modal re-render when array is updated
I’m pretty sure this is a simple issue but its stumped me. Run down: Essentially I have a list of files displayed on a table as table cells. When one is selected it becomes highlighted and is added to an array, I also can remove an item from my array by clicking again on it. Then Once I hit a