哪个帮个忙,把PHP函数修改为JS函数,多谢
程序员文章站
2024-01-16 13:15:46
...
哪个帮个忙,把PHP函数修改为JS函数,谢谢!
function bmrs($weight=0,$sex=1,$age){
switch ($age) {
case $age>=0 and $age
$x=array(1=>array(60.9,-54),2=>array(61.0,-51));
$y=1;
break;
case $age>=3 and $age
$x=array(1=>array(22.7,495),2=>array(22.5,499));
$y=1;
break;
case $age>=10 and $age
$x=array(1=>array(17.5,651),2=>array(12.2,746));
$y=1;
break;
case $age>=10 and $age
$x=array(1=>array(17.5,651),2=>array(12.2,746));
$y=0.95;
break;
case $age>=18 and $age
$x=array(1=>array(15.3,679),2=>array(14.7,496));
$y=0.95;
break;
case $age>=30 and $age
$x=array(1=>array(11.6,879),2=>array(8.7,829));
$y=0.95;
break;
case $age>=60:
$x=array(1=>array(13.5,487),2=>array(10.5,596));
$y=0.95;
break;
default:
break;
}
return ceil(($x[$sex][0]*$weight+$x[$sex][1])*$y); //对浮点数进行四舍五入
}
自带参数这几个,前面二个是默认值吗?$weight=0,$sex=1,$age
这二个代码,修改为JS,遇到了难度:
case $age>=0 and $age$x=array(1=>array(60.9,-54),2=>array(61.0,-51));
哪位帮个忙,把它修改为JavaScript的,谢谢。
------解决方案--------------------
function bmrs($weight=0,$sex=1,$age){
switch ($age) {
case $age>=0 and $age
$x=array(1=>array(60.9,-54),2=>array(61.0,-51));
$y=1;
break;
case $age>=3 and $age
$x=array(1=>array(22.7,495),2=>array(22.5,499));
$y=1;
break;
case $age>=10 and $age
$x=array(1=>array(17.5,651),2=>array(12.2,746));
$y=1;
break;
case $age>=10 and $age
$x=array(1=>array(17.5,651),2=>array(12.2,746));
$y=0.95;
break;
case $age>=18 and $age
$x=array(1=>array(15.3,679),2=>array(14.7,496));
$y=0.95;
break;
case $age>=30 and $age
$x=array(1=>array(11.6,879),2=>array(8.7,829));
$y=0.95;
break;
case $age>=60:
$x=array(1=>array(13.5,487),2=>array(10.5,596));
$y=0.95;
break;
default:
break;
}
return ceil(($x[$sex][0]*$weight+$x[$sex][1])*$y); //对浮点数进行四舍五入
}
自带参数这几个,前面二个是默认值吗?$weight=0,$sex=1,$age
这二个代码,修改为JS,遇到了难度:
case $age>=0 and $age$x=array(1=>array(60.9,-54),2=>array(61.0,-51));
哪位帮个忙,把它修改为JavaScript的,谢谢。
------解决方案--------------------
- JScript code
function bmrs(weight,sex,age){ var x=new Array(2),y=null; switch (true) { case age>=0 && age=3 && age=10 && age=10 && age=18 && age=30 && age=60: x[1]=new Array(13.5,487),x[2]=new Array(10.5,596); y=0.95; break; default: break; } return Math.ceil((x[1][0]*weight+x[1][1])*y); }相关文章
相关视频
下一篇: php 404错误页面实现代码