Skip to content

Instantly share code, notes, and snippets.

@schatteleyn
Created October 8, 2012 09:08
Show Gist options
  • Save schatteleyn/3851547 to your computer and use it in GitHub Desktop.
Save schatteleyn/3851547 to your computer and use it in GitHub Desktop.
Js Range
/*
Naive implementation of a range in Javascript. I needed that for a project, and coming from Ruby, I was disappointed to find there wasn't that.
So I implemented one.
b => beginning value of the range
e = ending value of the range
i => include or not the last value (.. or ... in Ruby)
*/
var array = new Array;
function range(array, b, e, i) {
if (typeof i == 'undefined') {
i = true; // if include is not defined, include by default
}
if (e < b){
if (i == true){
return array;
}
else {
return array.pop();
}
}
else {
array.unshift(e);
range(array, b, e - 1, i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment