This method is used to replace the Equal Value Comparison in the switch.
Generally, each comparison of the same value needs to be judged repeatedly.
The use of user-defined functions avoids repeated judgment and improves the efficiency.
The principle is simple: use an object to locate the value in the desired range.
The returned value can be a variable, an array, or a function.
Copy to ClipboardReference content: [www.bkjia.com] // The Switch is equivalent.
// Pass the parameter: The variable to be compared, the JSON format of the comparison value and return value
// It is more appropriate to set a default return value 'default '.
$ SEql = function (X, o, f, undefined ){
Return (f = o [X])! = Undefined? F: o ['default']
}
// Call example
GetX = function (C) {return $ SEql (C, {'-1': 100,0: 140,1: 187,2: 267,3: Random, 4: 427,5: 507,6: 587,7: 667,8: 747,9: 827,10: 865,11: 950})}; // returns the checkpoint X based on the column
GetY = function (R) {return $ SEql (R, {0: 75,1: 175, 2: 270,3: Random, 4: 470,5: 575})}; // returns the Y coordinate based on the row, used to coordinate the bottom and foot of a zombie
GetY1Y2 = function (R) {return $ SEql (R, {0: [86,180], 1: [181,280], 2: [281,385], 3: [], 4: [386,475], 5: [476,600]})}; // return the range of Y based on the row.