Range modifications: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added a comment re quotes in output)
(→‎{{header|Wren}}: Fixed output.)
Line 311: Line 311:


=={{header|Wren}}==
=={{header|Wren}}==
{{incomplete|Wren|Output formatting should not include spaces and square brackets}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Fmt
<lang ecmascript>import "/fmt" for Fmt
Line 362: Line 361:
}
}
}
}
}


var standard = Fn.new { |ranges| ranges.toString.replace("..", "-") }
var standard = Fn.new { |ranges| Fmt.v("s", 0, ranges, 0, ",", "").replace("..", "-") }


var add = 0
var add = 0
Line 381: Line 379:
var ranges = []
var ranges = []
var ops = [ [add, 77], [add, 79], [add, 78], [remove, 77], [remove, 78], [remove, 79] ]
var ops = [ [add, 77], [add, 79], [add, 78], [remove, 77], [remove, 78], [remove, 79] ]
System.print("Start: %(standard.call(ranges))")
Fmt.print("Start: $q", standard.call(ranges))
for (op in ops) fns[op[0]].call(ranges, op[1])
for (op in ops) fns[op[0]].call(ranges, op[1])


ranges = [1..3, 5..5]
ranges = [1..3, 5..5]
ops = [ [add, 1], [remove, 4], [add, 7], [add, 8], [add, 6], [remove, 7] ]
ops = [ [add, 1], [remove, 4], [add, 7], [add, 8], [add, 6], [remove, 7] ]
System.print("\nStart: %(standard.call(ranges))")
Fmt.print("\nStart: $q", standard.call(ranges))
for (op in ops) fns[op[0]].call(ranges, op[1])
for (op in ops) fns[op[0]].call(ranges, op[1])


ranges = [1..5, 10..25, 27..30]
ranges = [1..5, 10..25, 27..30]
ops = [ [add, 26], [add, 9], [add, 7], [remove, 26], [remove, 9], [remove, 7] ]
ops = [ [add, 26], [add, 9], [add, 7], [remove, 26], [remove, 9], [remove, 7] ]
System.print("\nStart: %(standard.call(ranges))")
Fmt.print("\nStart: $q", standard.call(ranges))
for (op in ops) fns[op[0]].call(ranges, op[1])</lang>
for (op in ops) fns[op[0]].call(ranges, op[1])
</lang>


{{out}}
{{out}}
<pre>
<pre>
Start: []
Start: ""
add 77 => [77-77]
add 77 => 77-77
add 79 => [77-77, 79-79]
add 79 => 77-77,79-79
add 78 => [77-79]
add 78 => 77-79
remove 77 => [78-79]
remove 77 => 78-79
remove 78 => [79-79]
remove 78 => 79-79
remove 79 => []
remove 79 =>


Start: [1-3, 5-5]
Start: "1-3,5-5"
add 1 => [1-3, 5-5]
add 1 => 1-3,5-5
remove 4 => [1-3, 5-5]
remove 4 => 1-3,5-5
add 7 => [1-3, 5-5, 7-7]
add 7 => 1-3,5-5,7-7
add 8 => [1-3, 5-5, 7-8]
add 8 => 1-3,5-5,7-8
add 6 => [1-3, 5-8]
add 6 => 1-3,5-8
remove 7 => [1-3, 5-6, 8-8]
remove 7 => 1-3,5-6,8-8


Start: [1-5, 10-25, 27-30]
Start: "1-5,10-25,27-30"
add 26 => [1-5, 10-30]
add 26 => 1-5,10-30
add 9 => [1-5, 9-30]
add 9 => 1-5,9-30
add 7 => [1-5, 7-7, 9-30]
add 7 => 1-5,7-7,9-30
remove 26 => [1-5, 7-7, 9-25, 27-30]
remove 26 => 1-5,7-7,9-25,27-30
remove 9 => [1-5, 7-7, 10-25, 27-30]
remove 9 => 1-5,7-7,10-25,27-30
remove 7 => [1-5, 10-25, 27-30]
remove 7 => 1-5,10-25,27-30
</pre>
</pre>