Js input length can get the nearest value and return the name

for example, enter L = 200to return the ip-5 in the array

var arr = [

["IP-1", 0]

["IP-2", 13.995886423358685]

["IP-3", 68.39963953170276]

["IP-4", 138.76858428768008]

["IP-5", 149.30208981161982]

["IP-6", 834.9549765566625]

["IP-7", 1090.4950690761289]

["IP-8", 1247.927742934118]

["IP-9", 1310.497021041034]

["IP-10", 1956.925744992665]

["IP-11", 2270.413239030439]

["IP-12", 3337.6333001873586]

]
Mar.12,2021

so first of all, the values in your array are sorted in order, and then look up and compare them according to dichotomy


.

setting an object according to the array is

function (value) {
  //  map
   const map = new Map() 
   //    name 
   arr.forEach(x => {
        const number = Math.abs(value - x[1])
        map.set(number, x[0])
    })
    //  map value
    return map.get(Math.min.apply(null,Array.from(map.keys())))
}
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-1ea4f23-1d16.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-1ea4f23-1d16.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?