I been practicing my algorithm solving skill by solving HackerRank problems. However, one of the problems is giving me a difficult time to understand. It is about calculating absolute difference between sum of diagonals in a square matrix “arr”. If the square matrix is like this: and the solution is like this: So, I came up with this solution: However,
Tag: arrays
How can I make a style event with addEventListener to multiple Nodes
I am trying to set a style event for a multiple images tags and I can’t: the error is in the anonymous function of the event when I put into a loop to make the effect individually and for all galleries in the document with images[i]. Why ? : Uncaught TypeError: Cannot set property ‘style’ of undefined at HTMLImageElement.<anonymous> Answer
Compare and update two arrays without losing mutated data
I have an array of objects contains data of persons then I add data to this array to each element where I end up with new key called money with value of 20 as the following and the array becomes like this Now, I have a new array with new data (new person) but missing the money I have added
How to create a el-table-tree structure with dynamic json data using javascript?
I have a task in which I need to convert an Array of Objects data to specified data tree structure for to display it in frontend tree-table. This below is my Array of Objects data. I have to change this data into this below following data structure. I have tried to do this using Recursion in methods but, I can’t
How to check if any array members can be sum up to the largest of them in JavaScript?
The goal is to create a function that takes an array of numbers as a parameter and checks if the largest of them can be obtained as the sum of any of the other numbers in the array. One condition is that negative numbers can be a part of the array taken as a parameter. The problem The function I
This code keeps returning ‘undefined’ for (names[i]). what am I doing wrong?
This code keeps returning ‘undefined’ for (names[i]). When I console.log() it loops through the array and prints Hello (names[i]) or Good Bye (names[i])what am I doing wrong? Answer Your issue is that you’re passing the name in as an argument to the speak function, however, in your definition of speak it doesn’t take an argument at all. You can fix
Getting array of school values from all objects using JS
Hello I am new to the JavaScript language. I have a table1.data property that’s an array of objects with data about a school like: Can I perhaps get an array of the telephone values from all the objects using JS? Please help. Answer All you need to do it traverse the items in the data, while grabbing the telephone field
How to extract all arrays in json object
I have a json object which has a collection of countries. Each country can have multiple regions which are represented in an array. I want to get the regions only and put all regions into one list.However when I map the data it doesn’t put all the regions in a list. What am I missing here? Here is the call
Why It shows Undefined when I try Access object in array in Next js
I’m trying to display sub Products of the main product so what I have tried is to get the product code from the URL and try to fetch sub-products that match the main product code the issue is it shows Undefined when I try implement like {subProducts.title} but when I console.log(subProducts) I get Array of subProducts that match with the
How to list multi level Sub-categories under their Categories if all the catgories are in the same array of objects?
I’m working on dropdown menu of categories with sub-categories, and some sub-categories has sub-categories too. i have array of categories with parent_id property which comes from server and i want to create another array with my custom structure in client side. parent_id : null is for main category. Categories array coming from server My expecting result My code this code