Elyse, magician-to-be, continues her training. She will be given several stacks of cards that she needs to perform her tricks. To make things a bit easier, she only uses the cards 1 to 10.
In this exercise, use built-in methods to analyse the contents of a vector.
Elyse wants to determine if a card is present in the stack -- in other words, if the stack contains a specific number.
card = 3;
does_stack_include_card(c(2, 3, 4, 5), card);
# => TRUEElyse wants to know the position (index) of a card in the stack.
If the card is not in the stack, return -1.
card = 2;
get_card_position(c(9, 7, 3, 2), card);
# => 4Elyse wants to know if every card is even -- in other words, if each number in the stack is an even number.
is_each_card_even(c(2, 4, 6, 7));
# => FALSEElyse wants to know if there is an odd number in the stack.
does_stack_include_odd_card(c(3, 2, 6, 4, 8));
# => TRUEElyse wants to know the value of the first card that is odd.
If there is no odd card in the stack, return -1.
get_first_odd_card(c(4, 2, 8, 7, 9));
# => 7Elyse wants to know the position of the first card that is even.
If there is no even card in the stack, return -1.
get_first_even_card_position(c(5, 2, 3, 1));
# => 2Elyse, magician-to-be, continues her training. She will be given several stacks of cards that she needs to perform her tricks. To make things a bit easier, she only uses the cards 1 to 10.
In this exercise, use built-in methods to analyse the contents of a vector.
Elyse wants to determine if a card is present in the stack -- in other words, if the stack contains a specific number.
card = 3;
does_stack_include_card(c(2, 3, 4, 5), card);
# => TRUEElyse wants to know the position (index) of a card in the stack.
If the card is not in the stack, return -1.
card = 2;
get_card_position(c(9, 7, 3, 2), card);
# => 4Elyse wants to know if every card is even -- in other words, if each number in the stack is an even number.
is_each_card_even(c(2, 4, 6, 7));
# => FALSEElyse wants to know if there is an odd number in the stack.
does_stack_include_odd_card(c(3, 2, 6, 4, 8));
# => TRUEElyse wants to know the value of the first card that is odd.
If there is no odd card in the stack, return -1.
get_first_odd_card(c(4, 2, 8, 7, 9));
# => 7Elyse wants to know the position of the first card that is even.
If there is no even card in the stack, return -1.
get_first_even_card_position(c(5, 2, 3, 1));
# => 2