Re:Deno Joins TC39
by amitport on Monday December 13, 2021 @07:42AM
(#29539030)
'range' a-la python
[ Parent
| on HN ]
Range a-la python is a generator and is pretty straightforward in js as is. There is no need for a complicated solution and/or as part of stdlib, imo:
function* range(x, y) {
while (x <= y) {yield x++}
// or ‘<‘ if you want half-open one
}
for (let n of range(3, 5)){
console.log(n)
}
array = [...range(3, 5)]
console.log(array)It's also straight forward to implement in python. It is common enough to be standard so people won't reinvent the wheel. And it should be available to people learning the language before they learn generators.
Array.prototype.indexOf is also pretty simple as are many core functions.