Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Design, HTML And CSS Forums (http://www.go4expert.com/forums/web-design-forum/)
-   -   Can you explain this codeż? (http://www.go4expert.com/forums/explain-code-t25323/)

raulcorrales 23Mar2011 05:55

Can you explain this codeż?
 
Hi to all the users.

I have find this code in this forum:


Code:

function MyFunction(a,b)

    return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
}


I've used for my program and it works, does what I want, but do not understand their ways.

Can you explain the functionż?

Thanks

Cristi1213 28Mar2011 16:11

Re: Can you explain this codeż?
 
The syntax is something like this: condition ? trueResult : falseResult;
First the condition is verified. If it is true than trueResult is returned, else falseResult is returned. In your example, the second one is evaluated first. If a1 is bigger than b1 1 is returned, else 0, than the second one is evaluated, -1 if a1 is smaller than b1, the previous result otherwise. That is -1 in case if a1<b1, 1 if a1>b1, 0 of they are equal.

pyasakumar 12Apr2011 16:58

Re: Can you explain this codeż?
 
Hello dear
I think also Its a condition. True and False Result


All times are GMT +5.5. The time now is 05:53.