The sum of a range using Javascript
<p>I wish to execute a program with output as :</p>

<pre><code>console.log(range(1, 10));  
// → [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  
console.log(range(5, 2, -1));  
// → [5, 4, 3, 2]  
console.log(sum(range(1, 10)));  
// → 55  
</code></pre>

<p>I am getting an error for array.length.Please find the code below:</p>

<pre><code>var array = [];

function range (arr){  
    var lower = Math.min(arr[0],arr[1]);    
    var upper = Math.max(arr[0],arr[1]);  

    for (var i=lower;i&lt;=upper;i++){  
        array.push(i);  
    }  
}  

function sum(array){  
    for(var i=0;i &lt; array.length;i++){  
        var total = total+array[i];  
    }  
}  

console.log(sum(range(1, 10)));  
</code></pre>

<p>I am at begineers level, please do help.
Thanks.</p>