How to gracefully judge the range of a number

The

question is as follows: pass in a value and how to elegantly judge the interval.
clipboard.png

except for using if.else.

is there any better choice?

Mar.14,2021


although using if-else is not elegant, it can achieve the highest efficiency. If you have to be elegant and there is no rule in the area you want to divide, you can only cycle through the whole area from beginning to end, just like the one upstairs.


give me an idea

function getRange(range,score){
    for(const r of range){
       ... 
   }
}
var range=[0,0.45,0.75,0.9]
getRange(range,0.5);

level = [0.45, 0.75, 0.9, 1.0]
def get_level(point):
    ret = 0
    while point > level[ret]:
        ret += 1
    return ret
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5b487-45620.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5b487-45620.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?