jquery Using ranges in switch cases?

后端 未结 4 798

Switch cases are usually like

Monday: 
Tuesday: 
Wednesday: 
etc. 

I would like to use ranges.

from 1-12: 
from 13-19:
fr         


        
4条回答
  •  逝去的感伤
    2021-01-05 16:57

    Late to the party, but upon searching for an answer to the same question, I came across this thread. Currently I actually use a switch, but a different way. For example:

    switch(true) {
        case (x >= 1 && x <= 12):
            //do some stuff
            break;
        case (x >= 13 && x <= 19):
            //do some other stuff                
            break;
        default:
            //do default stuff
            break;
    }
    

    I find this a lot easier to read than a bunch of IF statements.

提交回复
热议问题