Skip to content

Commit 233e57c

Browse files
authored
Add Longest Word in R (#4020)
1 parent b13b55b commit 233e57c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

archive/r/r/longest-word.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
longest_word_length <- function(input_string) {
2+
# Checking input
3+
args <- commandArgs(trailingOnly = TRUE)
4+
5+
if (length(args) == 0 || args == "") {
6+
cat("Usage: please provide a string\n")
7+
} else {
8+
# Split the string by whitespace and find the maximum word length in one line
9+
cat(max(nchar(unlist(strsplit(args[1], "[ \t\n\r]+")))), "\n")
10+
}
11+
}
12+
13+
longest_word_length()

0 commit comments

Comments
 (0)