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.

Revisions

  1. imorte created this gist Jul 30, 2017.
    15 changes: 15 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /**
    * 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));