开发者

Can I express these conditionals with a single math formula?

开发者 https://www.devze.com 2023-01-13 01:14 出处:网络
Not sur开发者_StackOverflow社区e of the best way to ask this question other than: I\'m writing a function that will accept a variable called \'x\'.

Not sur开发者_StackOverflow社区e of the best way to ask this question other than:

I'm writing a function that will accept a variable called 'x'.

function doIt(x){
  var y = someformula; //this is just a placeholder for the correct formula
  return y;
}

And here's what I expect returned:

if (x is between 0 and 9){ y = 0; }

if (x is between 10 and 19){ y = 32; }

if (x is between 20 and 29){ y = 64; }

if (x is between 30 and 39){ y = 96; }

and so on....

Any help is appreciated.

I'm doing it in JavaScript if it matters.


return Math.floor(x/10) * 32;
0

精彩评论

暂无评论...
验证码 换一张
取 消