Skip to content

Instantly share code, notes, and snippets.

@imorte
Created July 30, 2017 13:05
Show Gist options
  • Select an option

  • Save imorte/16d3e575750fb5610815461887c309d3 to your computer and use it in GitHub Desktop.

Select an option

Save imorte/16d3e575750fb5610815461887c309d3 to your computer and use it in GitHub Desktop.
recursive summ js
/**
* 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