Created
April 5, 2022 01:58
-
-
Save Lvcios/dc76a23e2a9ba020720c6b691757b30d to your computer and use it in GitHub Desktop.
Simple example of array sum using recursion
This file contains hidden or 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
| 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