Compare a list of strings: Difference between revisions

→‎{{header|Ruby}}: Minimalized according to discussion page
(Edge condition booboo)
(→‎{{header|Ruby}}: Minimalized according to discussion page)
Line 375:
 
=={{header|Ruby}}==
<lang ruby>aa = %w(AA AA AA AA)
puts " %s" % strings.each_cons(2).all?{|a,b| a< == b} # all equal?
abc = %w(AA AB AC)
strings == strings.sort # sorted?
acb = %w(AA CC BB)
end</lang>
[[], ["one"], aa, abc, acb].each do |strings|
puts "List : #{strings}"
puts " %s" % strings.all?{|a| strings[0] == a}
puts " %s" % strings.each_cons(2).all?{|a,b| a<b}
end</lang>
 
{{out}}
<pre>
List : []
true
true
List : ["one"]
true
true
List : ["AA", "AA", "AA", "AA"]
true
false
List : ["AA", "AB", "AC"]
false
true
List : ["AA", "CC", "BB"]
false
false
</pre>
 
=={{header|Tcl}}==
1,149

edits