In order to eliminate an array from a nested array, iterate through the remaining arrays using vanilla JavaScript. After removing the specified array, loop through each value within the nested arrays to complete the task

let linkMatrix = [
    [0,0,1,0],
    [1,0,0,1],
    [1,1,0,1],
    [0,1,0,0]
];


let newMatrix = [];

function linkToPage(){

    for(let j = 0; j < linkMatrix.length; j--){
        newMatrix = linkMatrix.splice(linkMatrix[j], 1);
        console.log(linkMatrix + " Here is linkMatrix");

        
            for(let i = 0; i < newMatrix.length; i++){
                newMatrix.splice(newMatrix[i]);
                console.log(newMatrix + " Here is newMatrix");
            }
        
    }

**My goal with this code is to iterate through the first array while excluding it from the loop. Then, I want to traverse the remaining arrays and extract the value at the index that was removed. To clarify further: if we had an array like arr = [[0,1],[1,0],[1,1]], removing [0,1] since it's arr[0], I plan to access the 0 index of the other arrays to retrieve the values 1 and 1. Next, I'll remove arr[1] and cycle through arr[0] and arr[2] to obtain the values at the 1 index of those arrays, resulting in [1,1]. **

**In essence, the desired outcome from my link matrix would be: 
    [0,0,1,0] = 2 
    [1,0,0,1] = 2
    [1,1,0,1] = 1
    [0,1,0,0] = 2
This is because there are 2 arrays pointing to the first array, as well as the second and fourth arrays, while only one array points to the third array.
    **

Answer â„–1

To calculate the sum of columns, you can add up the values in each column.

const
    getColSum = matrix => matrix.reduce((r, a) => a.map((v, i) => (r[i] || 0) + v), []);

console.log(...getColSum([[0, 0, 1, 0], [1, 0, 0, 1], [1, 1, 0, 1], [0, 1, 0, 0]));
console.log(...getColSum([[0, 0, 0], [1, 0, 0], [1, 1, 0]]));

An alternative method without using array methods extensively.

function getColSum (matrix) {
    const result = Array(matrix[0].length).fill(0);

    for (const row of matrix) {
        for (let i = 0; i < row.length; i++) result[i] += row[i];
    }

    return result;
}

console.log(...getColSum([[0, 0, 1, 0], [1, 0, 0, 1], [1, 1, 0, 1], [0, 1, 0, 0]));
console.log(...getColSum([[0, 0, 0], [1, 0, 0], [1, 1, 0]]));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm encountering an error where navigation.navigate is not being recognized as a function. Any ideas on

encounter an issue while navigating useEffect(() => { if (me === null) { navigation.navigate('Login'); } },[me]); The error is occurring here https://i.sstatic.net/s ...

Step-by-step guide on setting up ReactJS in Webstorm

I've been attempting to set up ReactJS in my WebStorm IDE, but I'm having trouble figuring out the correct way to do it. Is ReactJS an external library? Should I just add a new JavaScript file? I already have node.js installed on my computer and ...

Is it possible to move a directive within a limited parent element?

Is there a way to limit the movement of an angular.js drag directive within the confines of its parent element? You can see the problem I'm facing in this jsbin: http://jsbin.com/maxife/3/edit?html,css,js,output ...

Is it possible to make a distinctive choice from the dropdown menu?

I need help with my html page that has 10 dropdowns, each with options 1 to 10. How can I assign options uniquely to each dropdown? For example, if I select option 1 in dropdown 1, that option should be removed from the other dropdowns. If I deselect an ...

What is the process for updating selenium-webdriver if it is not globally installed on my system?

After installing selenium-webdriver with the command npm install selenium-webdriver (without the -g option), I found that the usual instruction of running webdriver-manager update did not work since it was installed locally. What is the correct way to upd ...

Request made to Ajax fetching complete webpage content

I have a page full of random tips at http://www.javaexperience.com/tips To display these tips on other pages of the website, I am using an ajax call to add the content returned by the call to a specific div's HTML. The code for the div is: <div ...

End-to-end testing using AngularJS Protractor is conducted to verify the message: 'Application has already been bootstrapped with this element'

Encountering an issue where my Protractor tests consistently fail with the following error message: UnknownError: Error Message => '[ng:btstrpd] App Already Bootstrapped with this Element '<html lang="en" data-ng-app="pmApp" class="js drag ...

Firebase (web) deploy encounters an issue due to stripe integration

I recently integrated Stripe into my Firebase function index.js: const stripe = require('stripe')('key'); and created a function for checkout sessions: exports.createCheckoutSession = functions.https.onCall(async(data, context) =&g ...

Tips for dynamically passing parameters to functions in JavaScript?

Looking for a solution to dynamically receive input from the user in my function: divResize = { myDiv:function(width, height) {...} } divResize.myDiv(100,400); I want to make these numbers interactive and changeable based on user input. How can I achie ...

IE 11 does not support JSON

Our web application runs smoothly on Windows 7 with IE 11 for the majority of users, except for one individual who encounters an error. One user is seeing the following error message: "JSON" is undefined This issue arises when the code executes the line ...

The ImportJSON function in Google Sheets is failing to return results when using a path with an

I am utilizing ImportJSON (https://github.com/bradjasper/ImportJSON) for the purpose of creating a spreadsheet and importing JSON data. /* * The provided JSON feed is flattened to create a two-dimensional array while importing it into a Google Spre ...

Is there a way I can turn off the dragging functionality in my situation?

Is there a method to disable the dragging functionality within a draggable element? $('#dragitem').draggable({ scroll : false, drag: function(event, ui){ //check if condition is met if(†...

Executing a custom object function in AngularJS by using the ng-click directive

As I navigate my way through AngularJS, I find myself grappling with the concept of calling a custom method of an object and wonder if there's a simpler approach: https://jsfiddle.net/f4ew9csr/3/ <div ng-app="myApp" ng-controller="myCtrl as myCtr ...

What issues are there with JavaScript?

I encountered an issue with my JavaScript code where it is not producing the expected result. var arr = new Array(); var firstobj = { cta: 0, ccc: 0, crc: 0 } for (var ta = 1; ta <= 10; ta++) { arr[ta] = firstobj; } arr[6].cta = 1; conso ...

Integrate the perfect-scrollbar jQuery plugin into RequireJS

Recently, I decided to explore RequireJS for my projects but I am still trying to understand its functionalities. I'm currently attempting to incorporate perfect-scrollbar, specifically the jQuery version, into my work. Here's a snippet from my ...

Having trouble converting a timestamp to a date in JavaScript

My database uses MongoDB and has a timestamp field with unique formats, such as: 1657479170.7300725 1657479170.7301126 1657479170.7301197 1657479170.9120467 1657479170.932398 Converting these timestamps to the date format YYYY-MM-DD yields the correct res ...

Create a dynamic animation using three.js

I am currently developing an application that optimizes pack placement in a truck using three.js for displaying 3D results. Below is the code snippet I'm working with: My goal is to create a moving scene where boxes are displayed one by one and move ...

Javascript leaping across intervals

I'm currently working on creating a unique JavaScript slideshow with a customized pause interval for each slide. Let's say I have a slideshow with 3 slides and I want the pause intervals to be as follows: 30 seconds 8 sec 8 sec |---- ...

What are the steps to implement the jQuery slide menu effect on a website?

When visiting the website , you may notice a symbol positioned in the top left corner of the site. By clicking on this symbol, a sleek div will slide out. How can this type of animation be achieved through javascript or jquery? ...

The process of generating a querystring from a form using jQuery is not functioning as expected

I am attempting to send an AJAX request, but I am facing an issue where the query string I am trying to construct turns out to be empty. <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>This project dem ...