Range consolidation: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
(→{{header|Wren}}: Now uses new core library method.) |
||
Line 2,237: | Line 2,237: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-math}} |
|||
As Wren already has a built-in Range class (which is not quite the same as what's required here), we create a Span class instead. |
As Wren already has a built-in Range class (which is not quite the same as what's required here), we create a Span class instead. |
||
<lang ecmascript> |
<lang ecmascript>class Span { |
||
class Span { |
|||
construct new(r) { |
construct new(r) { |
||
if (r.type != Range || !r.isInclusive) Fiber.abort("Argument must be an inclusive range.") |
if (r.type != Range || !r.isInclusive) Fiber.abort("Argument must be an inclusive range.") |
||
Line 2,259: | Line 2,256: | ||
if (_high < r.low) return [this, r] |
if (_high < r.low) return [this, r] |
||
if (r.high < _low) return [r, this] |
if (r.high < _low) return [r, this] |
||
return [Span.new( |
return [Span.new(_low.min(r.low).._high.max(r.high))] |
||
} |
} |
||