Home > Backend Development > PHP Tutorial > 哪个帮个忙,把PHP函数修改为JS函数,多谢

哪个帮个忙,把PHP函数修改为JS函数,多谢

WBOY
Release: 2016-06-13 13:26:39
Original
859 people have browsed it

哪个帮个忙,把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的,谢谢。



------解决方案--------------------

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); 

} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template