Last active
August 29, 2015 14:04
-
-
Save tonyonodi/4b2db10170419dc5f18f to your computer and use it in GitHub Desktop.
Lisp like javascript
This file contains 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
var range = function(a, b) { | |
var array, | |
direction; | |
array = new Array(); | |
direction = ( b - a ) / Math.abs( b - a ); | |
var i; | |
for ( i = a; i <= b; i += direction ) | |
array.push( i ); | |
return array; | |
} | |
var sum = function( array ) { | |
var total, | |
argIsArray; | |
argIsArray = array instanceof Array; | |
if( ! argIsArray ) | |
return NaN; | |
total = 0; | |
var i; | |
for ( i = 0; i < array.length; i++ ) | |
total += array[ i ]; | |
return total; | |
} | |
// the crux | |
console.log(sum(range(1, 10))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment