AdjacentSumRecursion

 avatar
user_1671475754
javascript
2 years ago
414 B
5
Indexable
Never
let adjacentSums = function(array) {
  let answer = [];
  
  //base case
  if(array.length === 1) return answer;
  
  //logic - take two numbers, add, shift, and push to answer
  let num1 = array.shift();
  let num2 = array[0];
  answer.push(num1 + num2);
  
  //recurse, then return combined answer
  let answer_from_recursing = adjacentSums(array);
  return answer.concat(answer_from_recursing);
};