Discuss / JavaScript / O(1) level algorithm (doge)

O(1) level algorithm (doge)

Topic source

生而为弟

#1 Created at ... [Delete] [Delete and Lock User]

var bmi = weight / height / height;

var trans_bmis = [bmi - 18.5 < 0, bmi - 25 < 0, bmi - 28 < 0, bmi - 32 < 0];

var std = ["过轻", "正常", "过重", "肥胖", "严重肥胖"];

var idx = trans_bmis.indexOf(true);

if (idx === -1) {

    idx = 4;

}

console.log(std[idx]);

生而为弟

#2 Created at ... [Delete] [Delete and Lock User]

replace time with space

张中硕

#3 Created at ... [Delete] [Delete and Lock User]

厉害

雏鹰

#4 Created at ... [Delete] [Delete and Lock User]

牛人,学习了

江K60

#5 Created at ... [Delete] [Delete and Lock User]

相比之下我们挨个老实写简直就是toyCode

~曉瘋~

#6 Created at ... [Delete] [Delete and Lock User]

var bmi = weight / height / height;

var trans_bmis = [bmi - 18.5 < 0, bmi - 25 < 0, bmi - 28 < 0, bmi - 32 < 0,bmi - 32 >= 0];

var std = ["过轻", "正常", "过重", "肥胖", "严重肥胖"];

var idx = trans_bmis.indexOf(true);

console.log(std[idx]);

谁可以解释一下这个解法的优势在什么地方?谢谢


  • 1

Reply