Integer comparison: Difference between revisions

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>deffinal comparisonrels = {[ a(-1) : '<', b0 -: '==', 1 : '>' ].asImmutable()
def comparisonSpaceship = { a, b ->
def rels = [ (-1) : '<', 0 : '==', 1 : '>' ]
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}}==
Anonymous user