Sorting algorithms/Merge sort: Difference between revisions

Content added Content deleted
m (→‎{{header|Tailspin}}: Neater expression)
m (→‎{{header|Wren}}: Minor tidy)
Line 7,700: Line 7,700:


=={{header|Wren}}==
=={{header|Wren}}==
<syntaxhighlight lang="ecmascript">var merge = Fn.new { |left, right|
<syntaxhighlight lang="wren">var merge = Fn.new { |left, right|
var result = []
var result = []
while (left.count > 0 && right.count > 0) {
while (left.count > 0 && right.count > 0) {
Line 7,732: Line 7,732:
}
}


var as = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
var array = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
for (a in as) {
for (a in array) {
System.print("Before: %(a)")
System.print("Before: %(a)")
a = mergeSort.call(a)
a = mergeSort.call(a)
Line 7,751: Line 7,751:
Alternatively we can just call a library method.
Alternatively we can just call a library method.
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascript">import "/sort" for Sort
<syntaxhighlight lang="wren">import "./sort" for Sort


var as = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
var array = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
for (a in as) {
for (a in array) {
System.print("Before: %(a)")
System.print("Before: %(a)")
a = Sort.merge(a)
a = Sort.merge(a)