-
-
Save 13protons/6ab78802c6fedf844415 to your computer and use it in GitHub Desktop.
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
// 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