Compare a list of strings: Difference between revisions

m
(Initial FutureBasic task solution added)
(8 intermediate revisions by 7 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 965 ⟶ 987:
true
}</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|AWK}}
 
<syntaxhighlight lang=easylang>
proc test s$[] . .
ident = 1
ascend = 1
for i = 2 to len s$[]
h = strcmp s$[i] s$[i - 1]
if h <> 0
ident = 0
.
if h <= 0
ascend = 0
.
.
print s$[]
if ident = 1
print "all equal"
.
if ascend = 1
print "ascending"
.
print ""
.
test [ "AA" "BB" "CC" ]
test [ "AA" "AA" "AA" ]
test [ "AA" "CC" "BB" ]
test [ "AA" "ACB" "BB" "CC" ]
test [ "single_element" ]
</syntaxhighlight>
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
Line 975 ⟶ 1,029:
{
isEqual()
= nil == self.seekEach(self.FirstMember, (n,m => m.equal:n.Inverted != n));
isAscending()
Line 984 ⟶ 1,038:
later.next();
^ nil == former.zipBy(later, (prev,next => next <= prev )).seekEach::(b => b)
}
}
Line 998 ⟶ 1,052:
public program()
{
testCases.forEach::(list)
{
console.printLine(list.asEnumerable()," all equal - ",list.isEqual());
Line 1,011 ⟶ 1,065:
AA,BB,CC ascending - true
AA,AA,AA all equal - true
AA,AA,AA ascending - falsetrue
AA,CC,BB all equal - false
AA,CC,BB ascending - false
Line 1,149 ⟶ 1,203:
Application code is hard to write and hard to read when low-level code is mixed in with application code.
It is better to hide low-level code in general-purpose code-libraries so that the application code can be simple.
Here is my solution using LIST.4TH from my novice-package: httphttps://www.forthforth2020.org/beginners-to-forth/a-novice.html-package
<syntaxhighlight lang="forth">
: test-equality ( string node -- new-string bad? )
Line 1,298 ⟶ 1,352:
printf @"List elements are lexically equal."
else
printf @"List elmentselements not lexically equal."
end if
if ( fn ListIsInLexicalOrder( temp ) == YES )
printf @"List elements are in ascending order."
else
printf @"List elmentselements not in ascending order."
end if
CFArrayRef sorted = fn ArraySortedArrayUsingSelector( temp, @"compare:" )
Line 1,323 ⟶ 1,377:
 
Input array elements: aaa aab aba baa
List elmentselements not lexically equal.
List elements are in ascending order.
List elements sorted in ascending order: aaa aab aba baa
 
Input array elements: caa aab aca abc
List elmentselements not lexically equal.
List elmentselements not in ascending order.
List elements sorted in ascending order: aab abc aca caa
</pre>
 
 
=={{header|Go}}==
Line 2,677 ⟶ 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 butput in between all of the elements of the argument list ''(or in technical terms, it [[wp:Fold_(higher-order_function)|folds/reduces]] the list using that operator, while taking into account the operator's inherent [https://design.raku.org/S03.html#Operator_precedence associativity] and identity value)'':
 
<syntaxhighlight lang="raku" line>[eq] @strings # All equal
Line 3,271 ⟶ 3,324:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "./sort" for Sort
 
var areEqual = Fn.new { |strings|
55

edits