Anonymous user
Integer comparison: Difference between revisions
→"Spaceship" (compareTo) Operator
m (added whitespace and bullet points to the task's preamble.) |
|||
Line 1,154:
==="Spaceship" (compareTo) Operator===
Using spaceship operator and a lookup table:
<lang groovy>
def comparisonSpaceship = { a, b ->
println "a ? b = ${a} ? ${b} = a ${rels[a <=> b]} b"
}</lang>
Line 1,168:
a ? b = 2000 ? 300000 = a < b
a ? b = 2000 ? 2000 = a == b</pre>
=={{header|Harbour}}==
|