1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to find diagonal value

Discussion in 'Programming/Internet' started by Enamul Haque, Sep 12, 2018.

  1. Enamul Haque

    Enamul Haque Guest

    I want find the sum of the values of an array. The array may be like this

    const maxtrix = [
    [1, 2, 3, 4],
    [5, 10, 7, 5],
    [8, 11, 15, 9],
    [6, 19, 4, 14],
    ]


    I want to find the value like this [4, 7, 11, 6] in an array.

    I tried to do this but I couldn't organise the code.

    Here is the code what I wrote:

    const maxtrix = [
    [1, 2, 3, 4],
    [5, 10, 7, 5],
    [8, 11, 15, 9],
    [6, 19, 4, 14],
    ]

    // right - 4, 7, 11, 6

    let left = 0

    let rowLenth = maxtrix.length - 1;
    let colLength = maxtrix[0].length - 1;


    maxtrix.forEach((a, r) => {
    a.forEach((b, c) => {
    console.log(maxtrix[r][colLength - c])
    })
    })

    Login To add answer/comment
     

Share This Page