8780 ! |
8780 ! |
8781 |
8781 |
8782 indexOf:anElement startingAt:start step:step |
8782 indexOf:anElement startingAt:start step:step |
8783 "search the collection for anElement, starting the search at index start; |
8783 "search the collection for anElement, starting the search at index start; |
8784 if found, return the index otherwise return 0. |
8784 if found, return the index otherwise return 0. |
|
8785 Only look at every step element. |
8785 The comparison is done using = |
8786 The comparison is done using = |
8786 (i.e. equality test - not identity test)." |
8787 (i.e. equality test - not identity test)." |
8787 |
8788 |
8788 |startIndex "{ Class: SmallInteger }" |
8789 |startIndex "{ Class: SmallInteger }" |
|
8790 stepCount "{ Class: SmallInteger }" |
8789 stop "{ Class: SmallInteger }" | |
8791 stop "{ Class: SmallInteger }" | |
8790 |
8792 |
8791 startIndex := start. |
8793 startIndex := start. |
8792 stop := self size. |
8794 stop := self size. |
8793 startIndex to:stop by:step do:[:index | |
8795 stepCount := step. |
|
8796 startIndex to:stop by:stepCount do:[:index | |
8794 anElement = (self at:index) ifTrue:[^ index]. |
8797 anElement = (self at:index) ifTrue:[^ index]. |
8795 ]. |
8798 ]. |
8796 ^ 0 |
8799 ^ 0 |
8797 |
8800 |
8798 " |
8801 " |
8799 args: anElement : <object> |
8802 args: anElement : <object> |
8800 start : <integer> |
8803 start : <integer> |
|
8804 step : <integer> |
8801 |
8805 |
8802 returns: elementIndex - if found |
8806 returns: elementIndex - if found |
8803 0 - if not found |
8807 0 - if not found |
8804 " |
8808 " |
8805 |
8809 |
8807 #(10 20 30 40 10 20 30 40) indexOf:40 startingAt:5 |
8811 #(10 20 30 40 10 20 30 40) indexOf:40 startingAt:5 |
8808 #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5 |
8812 #(10 20 30 40 10 20 30 40) indexOf:40.0 startingAt:5 |
8809 " |
8813 " |
8810 |
8814 |
8811 "Created: / 18-09-2018 / 14:06:32 / Stefan Vogel" |
8815 "Created: / 18-09-2018 / 14:06:32 / Stefan Vogel" |
|
8816 "Modified (comment): / 22-10-2019 / 19:57:19 / Stefan Vogel" |
8812 ! |
8817 ! |
8813 |
8818 |
8814 indexOfAny:aCollection |
8819 indexOfAny:aCollection |
8815 "search the collection for an element in aCollection. |
8820 "search the collection for an element in aCollection. |
8816 if found, return the index otherwise return 0. |
8821 if found, return the index otherwise return 0. |