4 ms·
Yeah but in python you would just use a generator for that.
by sametmax 7y ago
Yeah but in python you would just use a generator for that.
- jacobolus 7y agoIn python you could use just a regular function with a for loop. You can do that in javascript too. But the versions using smaller components can be faster to write and more composable. Really depends what kind of style you like and what you are trying to do.. const min_max = function min_max(iterable) { const it = iterable[Symbol.iterator](); const {value, done} = it.next(); if (done) return; let min = value, max = value; for (let x of it) { min = Math.min(min, x); min = Math.max(max, x); } return [min, max]; } min_max(readings); Anywhere that would be appropriate for a generator in python can also be a generator in Javascript though.
- sametmax 7y agoGenerator expressions exist for that in python.