Compare a list of strings: Difference between revisions
m
→{{header|Bruijn}}
m (→{{header|Wren}}: Minor tidy) |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 677:
test1 lstC succeeds
test2 lstC fails</pre>
=={{header|Bruijn}}==
{{trans|Haskell}}
<syntaxhighlight lang="bruijn">
:import std/String .
all-eq? [land? (zip-with eq? 0 (tail 0))]
all-gt? [land? (zip-with lt? 0 (tail 0))]
# --- tests ---
list-a "abc" : ("abc" : {}("abc"))
list-b "abc" : ("def" : {}("ghi"))
:test (all-eq? list-a) ([[1]])
:test (all-eq? list-b) ([[0]])
:test (all-gt? list-a) ([[0]])
:test (all-gt? list-b) ([[1]])
</syntaxhighlight>
=={{header|C}}==
Line 999 ⟶ 1,021:
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
Line 1,007 ⟶ 1,029:
{
isEqual()
= nil == self.seekEach(self.FirstMember, (n,m => m
isAscending()
Line 1,016 ⟶ 1,038:
later.next();
^ nil == former.zipBy(later, (prev,next => next <= prev )).seekEach::(b => b)
}
}
Line 1,030 ⟶ 1,052:
public program()
{
testCases.forEach::(list)
{
console.printLine(list.asEnumerable()," all equal - ",list.isEqual());
Line 1,043 ⟶ 1,065:
AA,BB,CC ascending - true
AA,AA,AA all equal - true
AA,AA,AA ascending -
AA,CC,BB all equal - false
AA,CC,BB ascending - false
Line 2,708 ⟶ 2,730:
(formerly Perl 6)
In Raku, putting square brackets around an [[wp:Infix_notation|infix]] operator turns it into a listop that effectively works as if the operator had been
<syntaxhighlight lang="raku" line>[eq] @strings # All equal
|