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