Last active
July 16, 2016 20:13
-
-
Save crmejia/977d547a51eec3fb50aa360b6ff597f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 valid_element(element_name, proposed_symbol) | |
| #not parsing as is not required | |
| #checking size | |
| return false if proposed_symbol.size != 2 | |
| proposed_symbol.downcase! | |
| element_name.downcase! | |
| #checking both letters are present | |
| return false unless element_name.include?(proposed_symbol[0]) # && element_name.include?(proposed_symbol[1]) | |
| #checking order | |
| rest_of_name = element_name.split('').drop_while {|c| c != proposed_symbol[0]} . drop(1) | |
| return false unless rest_of_name.include?(proposed_symbol[1]) | |
| true | |
| end | |
| def test_run | |
| test_elements = [ 'Spenglerium, Ee', | |
| 'Zeddemorium, Zr', | |
| 'Venkmine, Kn', | |
| 'Stantzon, Zt', | |
| 'Melintzum, Nn', | |
| 'Tullium, Ty'] | |
| test_elements.each{|s| puts valid_element( s.split(', ').first, s.split(', ').last)} | |
| nil | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment