syntax for case ranges

Felipe Nascimento de Moura felipenmoura at gmail.com
Fri Jan 31 13:26:45 UTC 2020


Very interesting.

Once I wanted (and would have used a lot) something like a `switchMatch`.
It would work like this:

switchMatch(value) {
  case /\d+/: { ... }
  case /\s+/: { ... }
  case /.../: { ... }
  default: {
    console.log('Didn't match any of the options');
  }
}

Of course you can have a regex like `(\d+)|(\s+)|...` but it would be more
readable and would allow situations like yours to be easily solved, read,
thought and taught.

[ ]s

*--*

*Felipe N. Moura*
Web Developer, Google Developer Expert
<https://developers.google.com/experts/people/felipe-moura>, Founder of
BrazilJS <https://braziljs.org/>, Nasc <http://nasc.io/> and On2
<https://on2.dev/>.

Website:  http://felipenmoura.com / http://nasc.io/
Twitter:    @felipenmoura <http://twitter.com/felipenmoura>
Facebook: http://fb.com/felipenmoura
LinkedIn: http://goo.gl/qGmq
---------------------------------
* Changing  the  world*  is the least I expect from  myself!


On Fri, Jan 31, 2020 at 6:57 AM Sultan <thysultan at gmail.com> wrote:

> For example, the following:
>
> switch (value) {
>     case 0...9: break
>     case 'a'...'z': break
> }
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200131/5b57e7f1/attachment.html>


More information about the es-discuss mailing list