by Waterluvian · 7y ago · 0 comments
Anyone have a sensible pure JavaScript example for:
range(5).forEach(fn)
I haven't found one that felt small enough to use inline. It end up using traditional for loops. for (var n in 5) // n is in [0..5)
should just work as it does in Sciter. _.range(5).forEach(i => {/*...*/}) Array(5).fill().forEach(() => console.log('hello')) Array.from({ length: 5 }).forEach(...)
But I'm not sure what you gain from that compared to just wrapping a for loop in a function. You still don't get ranges the way you do in, say Ruby: ('a'..'z').each {|letter| puts letter }I'm guessing it constructs the whole array upfront. Maybe there's a generator way to do it too.