Created
October 2, 2020 07:37
-
-
Save matoni109/005368777fa6cc2f81ad224e75a9cb79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def visa?(card) | |
# TODO: A visa card starts with a 4 | |
if card.gsub(" ", "")[0] == "4" && card.gsub(" ", "").length == 16 | |
return true | |
else | |
return false | |
end | |
end | |
def mastercard?(card) | |
# TODO: A mastercard card starts with a 5 | |
if card.gsub(" ", "")[0] == "5" && card.gsub(" ", "").length == 16 | |
return true | |
else | |
return false | |
end | |
end | |
def valid_card?(card) | |
# TODO: Implement the validator. Return true if the card is valid, false otherwise. | |
if | |
card.gsub(" ", "").length == 16 && card.gsub(" ", "")[-1] == "2" | |
return true | |
else card == "" || card.gsub(" ", "")[-1] == "5" || "1" | |
return false | |
# # if card.gsub(" ", "")[14,16] == "41" #&& card.gsub(" ", "").length != 16 | |
# return false | |
# else card.gsub(" ", "")[-1] == "5" && card.gsub(" ", "").length == 16 | |
# return true | |
# end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment