#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 31 Aug 2017 20:10:59 +0200
changeset 22237 fb6d54514410
parent 22236 14865585b530
child 22238 ce1753b20f6d
#FEATURE by cg class: SequenceableCollection added: #indexOfFirstDifferenceWith:
SequenceableCollection.st
--- a/SequenceableCollection.st	Thu Aug 31 15:39:15 2017 +0200
+++ b/SequenceableCollection.st	Thu Aug 31 20:10:59 2017 +0200
@@ -2338,6 +2338,23 @@
     "Modified: / 27.3.1998 / 17:33:49 / cg"
 !
 
+indexOfFirstDifferenceWith:anotherCollection
+    "return the index of the first element which is different to the corresponding
+     element in anotherCollection. 0 if they are all the same.
+     The comparison is by equality, i.e. using #="
+     
+    ^ self with:anotherCollection findFirst:[:a :b | a ~= b] 
+
+    "
+     'hello' indexOfFirstDifferenceWith:'helLo' 
+     'hello' indexOfFirstDifferenceWith:'hello'   
+     'hello' indexOfFirstDifferenceWith:'hello1'   
+     'hello1' indexOfFirstDifferenceWith:'hello' 
+    "
+
+    "Created: / 31-08-2017 / 20:10:36 / cg"
+!
+
 isSameSequenceAs:otherCollection
     "Answer whether the receiver's size is the same as otherCollection's size,
      and each of the receiver's elements equal the corresponding element of otherCollection.