Asked 7 years ago
6 Jan 2017
Views 1073
noob

noob posted

how <=> (Spaceship ) Operator work in Ruby ?

how Spaceship Operator ( <=>) work ?
what it means when we say x<=>y and how it interact with array

[1,0,2] <=> [1,2,2] 

what this give us result ?


optional info i need is , all other language like PHP , Python , have Spaceship Operator ?
Rasi

Rasi
answered Nov 30 '-1 00:00

<=> operator check three condition in one check give differ return based on result
first value = second value return 0
first value < second value return 1
first value > second value return -1
suppose
a<=>b is check will return 0 if a==b
a<=>b is check will return 1 if a>b
a<=>b is check will return -1 if a<b

Post Answer