Last active
October 7, 2015 12:08
-
-
Save monolithed/3163163 to your computer and use it in GitHub Desktop.
Range function
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
/* | |
* Range | |
* @author: Alexander Guinness | |
* @version: 1.0 | |
* @license: MIT | |
* @date: 7/20/12 9:28 PM | |
*/ | |
function range (from, to, step) { | |
var array = []; | |
step = step || 1; | |
try { | |
for (var i = from.charCodeAt(0); i <= to.charCodeAt(0); i += step) { | |
array.push(String.fromCharCode(i)); | |
} | |
} | |
catch (error) { | |
for (var i = from; i <= to; i += step) { | |
array.push(i); | |
} | |
} | |
return array; | |
}; | |
console.log(range('a', 'e')); // ['a', 'c', 'e']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment