Skip to content

Instantly share code, notes, and snippets.

@monolithed
Last active October 7, 2015 12:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monolithed/3163163 to your computer and use it in GitHub Desktop.
Save monolithed/3163163 to your computer and use it in GitHub Desktop.
Range function
/*
* 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