>>>> But you can phrase that as
>>>
>>>> return x ? x : -x;
>>>
>>> No, you can't.
>>>
>>> Don't blame others for doing mistakes if you are doing them yourself. ;)
>
>> The guy took about 6 minutes to come up with the answer illustrated. My
>> problem was in only spending 6 seconds. :-/
>
> The problem is that the answer above doesn't work.
Yes, because I typed it too fast. What I meant to say was
return (x >= 0) ? x : -x;
which works as expected.
Post a reply to this message
|