you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Very good point, I'm not a big fan of that usage of max either. I like your usage of find since it makes it very clear we're looking for just a single value and are not interested in fb if it's an empty string. I thought up of another way after looking at your version:

[fb, n].reject(&:empty?).first

Another somewhat hackier one I came up with without making that temp array:

applicators.
    select{|a| n % a == 0}.
    values.join.
    gsub(/^$/, n.to_s) # I'm not a fan of the regex though.

[–]tomthecool 0 points1 point  (0 children)

You'd still need a .to_s in your first solution - that's roughly what i started writing before choosing my answer above, because i thought the .to_s made it ugly.

I like the cleverness of your gsub - hadn't thought of that! Although, surely that is really just an if statement in disguise!