Skip to content

Instantly share code, notes, and snippets.

@crmejia
Last active July 16, 2016 20:13
Show Gist options
  • Select an option

  • Save crmejia/977d547a51eec3fb50aa360b6ff597f4 to your computer and use it in GitHub Desktop.

Select an option

Save crmejia/977d547a51eec3fb50aa360b6ff597f4 to your computer and use it in GitHub Desktop.
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