MCPcopy Create free account
hub / github.com/appacademy/Module-1-Resources / adjacentSum

Function adjacentSum

w1/d3/eod.js:26–41  ·  view source on GitHub ↗
(numArray)

Source from the content-addressed store, hash-verified

24*/
25
26function adjacentSum(numArray) {
27 // your code here
28 let sumArr = [];
29
30 for(let i = 0; i < numArray.length; i++) {
31
32 // console.log('Hi!')
33 let currNum = numArray[i];
34 // console.log(currNum)
35 let nextNum = numArray[i + 1]
36 // console.log(nextNum)
37
38 if (nextNum === undefined) return sumArr;
39 else sumArr.push(currNum + nextNum)
40 }
41}
42
43// console.log(adjacentSum([3, 7, 2, 11])); // [10, 9, 13], because [ 3+7, 7+2, 2+11 ]
44// console.log(adjacentSum([2, 5, 1, 9, 2, 4])); // [7, 6, 10, 11, 6], because [2+5, 5+1, 1+9, 9+2, 2+4]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected