I am trying to study Array.reduce. And I was given the following task: Input data: And I need to get this data in the output I tried to write some code, but I have no idea how to do it correctly. How can I solve this problem? Code: Answer Corrected the logic
Category: Questions
Convert timestamp from API to date app script
Running in App script, google sheet. I get timestamp from API and return this result: Now I want to convert this timestamp to date to be like that: 10/28/2021 10:30 I try this code: var convertDate = Utilities.formatDate(timestamp, “GMT”, “MM-dd-yyyy HH:mm:ss”); but not working any sug…
How to filter object based on conditional argument?
I am calling a function with two arguments, Arg 1: Object {a:1, b:2, c:3, d:4} Arg 2: Condition ((prop, key) => prop >= 3)) Here based on the condition we need to filter the object and provide the result as array of objects. The code that I have tried, Current Result: [3,4] Expected Result: [{c:3}, {d:4…
cloneNode without losing event listener
how can i move my html element without losing the event listener attached to the button? The child button’s event listener does not work after cloning and removing the original element Answer You’ve said you want to move it, but what you’re doing is cloning it, saving the clone, and then rem…
How to pass a function to a component using arrow function?
FYI: I am using ES6 on ReactJS I have a switcher. I need it to switch to the other side when clicked. If click on the side that is currently active does nothing. Here is my sample code Here is the code inside the CustomSwitcher However I got this error As I understand, when passing a function down to a
How it’s possible to have same variable and function name in JavaScript
We usually use React.memo as follow We have a MyComponent function and a MyComponent variable in the same scope, Why the syntax is correct and we have no runtime error like Uncaught SyntaxError: Identifier ‘MyComponent’ has already been declared? Answer Given a function declaration (you don’…
React is not getting uninstalled in windows
I am not able to uninstall react app in windows 10. I tried everything which is in stackoverflow but it is not getting uninstalled. I am using npm . Even I removed nodejs, still it is not working. I actually need to use latest version so when I installed nodejs and react again it is still picking old version …
Change only one specific value from dynamic input field
i need some help. So i have: This iterate some data from Firebase Firestore into the web page. Then there’s an input field to change the age. If i want to change doc.age, how do i do that? If i just write it like above, then if there are 10 names, all names will have the same age. How do
What’s the best way to code an input tag with certain locked characters?
Introduction I would like to make an input of a fixed length that you can only fill some of the characters, for instance let’s say I have __llo w_rld! and i want the user to fill in the gaps, but not allow to modify the prefilled characters. Ideas I thought of using an input tag for each character and m…
What is Unexpected token a in JSON at position 0?
I am getting an error that says SyntaxError: Unexpected token a in JSON at position 0 and I cannot find any information on what “a” means. I know that the JSON is not undefined. Can anyone help me understand what is causing this error? Here is the code block that is causing the error: Answer Unexp…