Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

diagonal Difference in 2D arrays javascript

function diagonalDifference(arr) {
    let leftToRight=[], rightToleft = []
    arr.forEach((ar, index)=>{
        leftToRight.push(ar[0+index])
        rightToleft.push(ar[ar.length - 1 - index])
    })
    const leftDiagnolSum = leftToRight.reduce((acc, val)=>acc+val)
    const rightDiagnolSum = rightToleft.reduce((acc, val)=>acc+val)
    return Math.abs(leftDiagnolSum - rightDiagnolSum)

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: find and filter 
Javascript :: find index in array javascript 
Javascript :: react prevent component from update once mounted 
Javascript :: round number at 2 decimal places 
Javascript :: add items to a list in a document monoose 
Javascript :: how would you check if a number is an integer in javascript 
Javascript :: js hide div 
Javascript :: .toJSON() in sequelize 
Javascript :: how do i check if JQuery checkbox is checked 
Javascript :: javascript text replace 
Javascript :: vuejs check object key exist 
Javascript :: bindparam 
Javascript :: get font size jquery 
Javascript :: javascript get same elments from multiple arrays 
Javascript :: javascript convert file to array 
Javascript :: updating a key value on javascript object es6 
Javascript :: get element type javascript 
Javascript :: how to add youtube videos to react app 
Javascript :: how to break the foreach loop in javascript 
Javascript :: timepicker in jquery 
Javascript :: js how to check is array empty es6 
Javascript :: how to get common elements from two array in javascript using lodash 
Javascript :: node js server 
Javascript :: require a json as a string 
Javascript :: nuxt query params 
Javascript :: run function then empty it 
Javascript :: javascript two decimal places after division 
Javascript :: add property to all documents mongo 
Javascript :: mongoose update push 
Javascript :: string to date js 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =