Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active August 9, 2022 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/7f98d6890bbb8587794f9f8f170f4c7a to your computer and use it in GitHub Desktop.
Save McLarenCollege/7f98d6890bbb8587794f9f8f170f4c7a to your computer and use it in GitHub Desktop.
Sum Skip Array

Give an multi-dimensional array, starting from the first row, traverse the array by skipping every next row and calculate the sum of traversed elements and return it.

function traverseArray(arr){
// write your code here
}
let arr1 = [[1,2,3],
           [4,5,6],
           [7,8,9]];
let arr2 = [[1,2,3,4],
            [5,6,7,8],
            [9,10,11,12],
            [13,14,15,16]];
console.log(traverseArray(arr1));// should return 30
console.log(traverseArray(arr2));// should return 52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment