Simple Array Generator
Here are a few different ways to create an array. So simple and fast.
Usage 1 (Lower Bottom)
const ARRAY_GEN = (x,y) => (function*(){
while (x <= y) yield x++;
})();
for (let res of ARRAY_GEN(1,5)){
console.log(res);
}
Output:
{
"output": "
1
2
3
4
5
"
}
Usage 2 (Side by Side)
const ARRAY_GEN = (x,y) => Array.from((function*(){
while (x <= y) yield x++;
})());
console.log(ARRAY_GEN(1,5));
Output:
{
"output": "[1, 2, 3, 4, 5]"
}
Usage 3 (Letters)
function range(s, e, str){
function *gen(s, e, str){
while(s <= e){
yield (!str) ? s : str[s]
s++
}
}
if (typeof s === 'string' && !str)
str = 'abcdefghijklmnopqrstuvwxyz'
const from = (!str) ? s : str.indexOf(s)
const to = (!str) ? e : str.indexOf(e)
return [...gen(from, to, str)]
}