new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
6
Task/Search-a-list/R/search-a-list-1.r
Normal file
6
Task/Search-a-list/R/search-a-list-1.r
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
find.needle <- function(haystack, needle="needle", return.last.index.too=FALSE)
|
||||
{
|
||||
indices <- which(haystack %in% needle)
|
||||
if(length(indices)==0) stop("no needles in the haystack")
|
||||
if(return.last.index.too) range(indices) else min(indices)
|
||||
}
|
||||
8
Task/Search-a-list/R/search-a-list-2.r
Normal file
8
Task/Search-a-list/R/search-a-list-2.r
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
haystack1 <- c("where", "is", "the", "needle", "I", "wonder")
|
||||
haystack2 <- c("no", "sewing", "equipment", "in", "here")
|
||||
haystack3 <- c("oodles", "of", "needles", "needles", "needles", "in", "here")
|
||||
|
||||
find.needle(haystack1) # 4
|
||||
find.needle(haystack2) # error
|
||||
find.needle(haystack3) # 3
|
||||
find.needle(haystack3, needle="needles", ret=TRUE) # 3 5
|
||||
Loading…
Add table
Add a link
Reference in a new issue