Created
September 25, 2018 19:42
-
-
Save ramsunvtech/dbc7a064048af001d3cf9a594cd2c11a to your computer and use it in GitHub Desktop.
Sum of Three Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1,2,3,1,1]; | |
var b = [4,5,6,1]; | |
var c = [1,1,1]; | |
function sumArray(a,b,c) { | |
const max = Math.max(a.length, b.length, c.length); | |
const sumList = []; | |
for(let i = 0; i < max; i++) { | |
sumList.push((a[i] || 0) + (b[i] || 0) + (c[i] || 0)); | |
} | |
return sumList; | |
} | |
sumArray(a,b,c); // [6,8,10,2,1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment