Jump to content

Common sorted list: Difference between revisions

Added Wren
m (→‎{{header|REXX}}: added the computer programming language REXX.)
(Added Wren)
Line 73:
<pre>
common sorted list elements are: [1,3,4,5,7,8,9]
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-seq}}
{{libheader|Wren-sort}}
<lang ecmascript>import "/seq" for Lst
import "/sort" for Sort
 
var distinctUnion2 = Fn.new { |l1, l2| Lst.distinct(l1 + l2) }
 
var distinctUnionN = Fn.new { |ll|
var n = ll.count
if (n == 0) return ll
if (n == 1) return ll[0]
var first2 = distinctUnion2.call(ll[0], ll[1])
if (n == 2) return first2
return ll.skip(2).reduce(first2) { |acc, l| distinctUnion2.call(acc, l) }
}
 
var ll = [[5, 1, 3, 8, 9, 4, 8, 7], [3, 5, 9, 8, 4], [1, 3, 7, 9]]
System.print("Distinct sorted union of %(ll) is:")
var u = distinctUnionN.call(ll)
Sort.insertion(u)
System.print(u)</lang>
 
{{out}}
<pre>
Distinct sorted union of [[5, 1, 3, 8, 9, 4, 8, 7], [3, 5, 9, 8, 4], [1, 3, 7, 9]] is:
[1, 3, 4, 5, 7, 8, 9]
</pre>
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.