Skip to content

Instantly share code, notes, and snippets.

@tonyonodi
Last active August 29, 2015 14:04
Show Gist options
  • Save tonyonodi/4b2db10170419dc5f18f to your computer and use it in GitHub Desktop.
Save tonyonodi/4b2db10170419dc5f18f to your computer and use it in GitHub Desktop.
Lisp like javascript
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