Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
imported>Arakov
m (→‎{{header|Wren}}: Minor tidy)
Line 5,215: Line 5,215:


=={{header|Wren}}==
=={{header|Wren}}==
<syntaxhighlight lang="ecmascript">var insertionSort = Fn.new { |a|
<syntaxhighlight lang="wren">var insertionSort = Fn.new { |a|
for (i in 1..a.count-1) {
for (i in 1..a.count-1) {
var v = a[i]
var v = a[i]
Line 5,227: Line 5,227:
}
}


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)")
insertionSort.call(a)
insertionSort.call(a)
Line 5,246: Line 5,246:
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)")
Sort.insertion(a)
Sort.insertion(a)