开发者

Can I express these conditionals with a single math formula?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜