Skip to content

Instantly share code, notes, and snippets.

@Lvcios
Created April 5, 2022 01:58
Show Gist options
  • Select an option

  • Save Lvcios/dc76a23e2a9ba020720c6b691757b30d to your computer and use it in GitHub Desktop.

Select an option

Save Lvcios/dc76a23e2a9ba020720c6b691757b30d to your computer and use it in GitHub Desktop.
Simple example of array sum using recursion
function sumArrayRecursive(arr){
if(arr.length == 1) return arr[0];
else if(arr.length == 0) return 0;
else{
return arr[arr.length - 1] + sumArrayRecursive(arr.slice(0, arr.length - 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment