Created
July 30, 2017 13:05
-
-
Save imorte/16d3e575750fb5610815461887c309d3 to your computer and use it in GitHub Desktop.
recursive summ js
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
| /** | |
| * Created by kirill on 30/07/2017. | |
| */ | |
| array = [1, 2, 3, 4]; | |
| function rec_sum(array) { | |
| if(array.length > 1) { | |
| return array[0] + rec_sum(array.slice(1)) | |
| } else { | |
| return array[0]; | |
| } | |
| } | |
| console.log(rec_sum(array)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment