Skip to content

Instantly share code, notes, and snippets.

@13protons
Forked from mattmccray/range.js
Last active August 29, 2015 14:07
Show Gist options
  • Save 13protons/6ab78802c6fedf844415 to your computer and use it in GitHub Desktop.
Save 13protons/6ab78802c6fedf844415 to your computer and use it in GitHub Desktop.
// 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