Exercise 13: Returning from a Function
Let's test your ability to return data from a function.
We'll cover the following
Problem Statement
Implement a function evenOdd
that takes a vector
of numbers as input and returns a vector
where each element of the output vector has the string “even” or “odd” depending on the corresponding element of the input vector
.
Input
A testVariable
containing the vector
to be tested.
Output
A vector
where each element is either “even” or “odd” depending on the state of the corresponding element of the input testVariable
vector.
Sample Input
testVariable <- c(78, 100, 2)
Sample Output
"even" "even" "even"
Test Yourself
Write your code in the given area. If you get stuck, you can look at the solution.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy