Hi all!
const
Whitespace = {' ', '\t', '\v', '\c', '\n', '\f'},
Digits = {'0'..'9'},
DigitsWithSep = Digits + {'.', ',', '_'},
OpChars = ['^', '/', '*', '-', '+'],
Is it possible to do something like this in Javascript?
Notes
- I'm creating a parser of a text
- I would like to know if it is possible to do something like this in Javascript, curiosity question
- I would be happy if someone would read and answer my question. ;D
What would that do, exactly?
You can do:
const Whitespace= = new Set([' ', '\t', '\v', '\c', '\n', '\f']);
const Digits = Array.from({ length: 9 }, (_, i) => i);
const DigitsWithSep = Digits.concat('.', ',', '_');
const OpChars = new Set(['^', '/', '*', '-', '+']);```
etc, though.
1 Like
That hurts my eyes. I'd like to see Number.range() get some traction to help out there.
1 Like
If arrays work (as opposed to sets), then this would work as well:
const
Whitespace = [' ', '\t', '\v', '\c', '\n', '\f'],
Digits = [...'0123456789'],
DigitsWithSep = [ ...Digits, '.', ',', '_'],
OpChars = ['^', '/', '*', '-', '+'],
2 Likes
@theScottyJam @senocular @ljharb thank you all for feedback!
I'm currently waiting for the Iterator Helpers proposal to move forward
2 Likes