We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defconvert_temp(temp,input_scale:String,output_scale:'celsius')conversion=[input_scale.strip.downcase.to_sym,output_scale.strip.downcase.to_sym]k_to_c=lambda{|k|k-273.15}c_to_k=lambda{|c|c+273.15}c_to_f=lambda{|c|(c*(9.0/5.0))+32.0}f_to_c=lambda{|f|(f-32.0)*(5.0/9.0)}caseconversionwhen[:kelvin,:kelvin]tempwhen[:celsius,:celsius]tempwhen[:fahrenheit,:fahrenheit]tempwhen[:kelvin,:celsius]k_to_c.call(temp)when[:celsius,:kelvin]c_to_k.call(temp)when[:kelvin,:fahrenheit]c_to_f.call(k_to_c.call(temp))when[:fahrenheit,:kelvin]c_to_k.call(f_to_c.call(temp))when[:celsius,:fahrenheit]c_to_f.call(temp)when[:fahrenheit,:celsius]f_to_c.call(temp)elseraiseStandardError,"Invalid Units: #{input_scale} or #{output_scale}"endend
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby - Methods - Keyword Arguments
You are viewing a single comment's thread. Return to all comments →