Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,38 @@
REBOL [
Title: "List Indexing"
URL: http://rosettacode.org/wiki/Index_in_a_list
]
locate: func [
"Find the index of a string (needle) in string collection (haystack)."
haystack [series!] "List of values to search."
needle [string!] "String to find in value list."
/largest "Return the largest index if more than one needle."
/local i
][
i: either largest [
find/reverse tail haystack needle][find haystack needle]
either i [return index? i][
throw reform [needle "is not in haystack."]
]
]
; Note that REBOL uses 1-base lists instead of 0-based like most
; computer languages. Therefore, the index provided will be one
; higher than other results on this page.
haystack: parse "Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo" none
print "Search for first occurance:"
foreach needle ["Washington" "Bush"] [
print catch [
reform [needle "=>" locate haystack needle]
]
]
print [crlf "Search for last occurance:"]
foreach needle ["Washington" "Bush"] [
print catch [
reform [needle "=>" locate/largest haystack needle]
]
]