Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created October 13, 2014 13:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattmccray/e8568b2855e84f8b7ab7 to your computer and use it in GitHub Desktop.
Save mattmccray/e8568b2855e84f8b7ab7 to your computer and use it in GitHub Desktop.
Creates a 'range' Array, extracted from Liquid.js
// Creates a 'range' Array, extracted from Liquid.js
function makeRange(from, to) {
var arr= [],
left= parseInt(from),
right= parseInt(to);
// Check if left and right are NaN, if so try as characters
if( isNaN(left + right) ) {
// TODO Add in error checking to make sure ranges are single
// character, A-Z or a-z, etc.
left = from.charCodeAt(0);
right = to.charCodeAt(0);
var limit = right-left+1;
for (var i=0; i<limit; i++) arr.push(String.fromCharCode(i+left));
}
else { // okay to make array
var limit = right-left+1;
for (var i=0; i<limit; i++) arr.push(i+left);
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment