Math equation help

Hi all!

I was wondering if there are any Math people here that would be able to construct an equation for me. The equation needs to return 1 when 10 is inputted, and 0 when any other number is inputted. (please try to make it as concise and efficient as possible).

Thanks in advance for anyone willing to help!

input === 10 ? 1 : 0

non-number inputs → you’re on your own

Hi! Thanks a lot for the reply!

Unfortunately, I was trying to avoid using ternary operators. I heard using Math functions are faster then ternary operators, and my task requires absolute performance.

not unfortunate at all! how about this

+(input === 10)
2 Likes

Thanks! This seems to be doing the job!

I also got this equation from ChatGPT, but needs a bit of tinkering: Math.abs(Math.sin(Math.PI * (x - 10) / 10));

update: ChatGPT got this which achieves what wh0 posted above:
Math.abs(Math.sin(Math.PI * (x - 10) / 10)) + (1 - Math.abs(x - 10) / (x - 10 + 1e-9));

qz: ternary seems slow
chatgpt: lemme get some method dispatch and trig out for you

edit: oops wrong parens

1 Like