我正在尝试创建一个函数,将 Javascript 中的米每秒 (m/s) 转换为蒲福氏尺度。我可以使用一系列 if 语句来完成此操作,但我更愿意将其替换为公式来为我动态计算。
到目前为止,我的研究使我能够实现以下目标:
function beaufort(ms) {
ms = Math.abs(ms);
if (ms <= 0.2) {
return 0;
}
if (ms <= 1.5) {
return 1;
}
if (ms <= 3.3) {
return 2;
}
if (ms <= 5.4) {
return 3;
}
if (ms <= 7.9) {
return 4;
}
if (ms <= 10.7) {
return 5;
}
if (ms <= 13.8) {
return 6;
}
if (ms <= 17.1) {
return 7;
} …Run Code Online (Sandbox Code Playgroud)