Which of the following is a favor? I want to change the PHP function to a JS function. thank you!

Source: Internet
Author: User
Which one is helpful? modify the PHP function to a JS function. thank you! Functionbmrs ($ weight = 0, $ sex = 1, $ age) {switch ($ age) {case $ age & gt; = 0and $ age & lt; 3: $ x = ar: which one is helpful? Change the PHP function to a JS function. thank you!
Function bmrs ($ weight = 0, $ sex = 1, $ age ){


Switch ($ age ){

Case $ age> = 0 and $ age <3:


$ X = array (1 => array (60.9,-54), 2 => array (61.0,-51 ));

$ Y = 1;


Break;



Case $ age> = 3 and $ age <10:

$ X = array (1 => array (22.7, 495), 2 => array (22.5, 499 ));
$ Y = 1;

Break;


Case $ age> = 10 and $ age <18:

$ X = array (1 => array (17.5, 651), 2 => array (12.2, 746 ));

$ Y = 1;
Break;

Case $ age> = 10 and $ age <18:

$ X = array (1 => array (17.5, 651), 2 => array (12.2, 746 ));
$ Y = 0.95;

Break;

Case $ age> = 18 and $ age <30:

$ X = array (1 => array (15.3, 679), 2 => array (14.7, 496 ));
$ Y = 0.95;

Break;

Case $ age> = 30 and $ age <60:

$ 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); // round the floating point number

}

Which of the following are built-in parameters? are the first two default values? $ Weight = 0, $ sex = 1, $ age

These two codes are modified to JS, and the difficulty is:

Case $ age> = 0 and $ age <3:
$ X = array (1 => array (60.9,-54), 2 => array (61.0,-51 ));


Which of the following is a favor? change it to JavaScript. thank you.



------ Solution --------------------
JScript code
function bmrs(weight,sex,age){    var x=new Array(2),y=null;    switch (true)    {        case age>=0 && age<3:            x[1]=new Array(60.9,-54),x[2]=new Array(61.0,-51);            y=1;            break;        case age>=3 && age<10:            x[1]=new Array(22.7,495),x[2]=new Array(22.5,499);            y=1;            break;        case age>=10 && age<18:            x[1]=new Array(17.5,651),x[2]=new Array(12.2,746);            y=1;            break;        case age>=10 && age<18:            x[1]=new Array(17.5,651),x[2]=new Array(12.2,746);            y=0.95;            break;        case age>=18 && age<30:            x[1]=new Array(15.3,679),x[2]=new Array(14.7,496);            y=0.95;            break;        case age>=30 && age<60:            x[1]=new Array(11.6,879),x[2]=new Array(8.7,829);            y=0.95;            break;        case 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); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.