Home > Enterprise >  I have this fizzbuzz problem and I really don't know how to solve it Can somebody help me?
I have this fizzbuzz problem and I really don't know how to solve it Can somebody help me?

Time:02-21

Convert ["a", nil, "b", "c", nil] and ["d", nil, "e", "f"] into ["af", "be", "cd"] using Ruby in one sentence Hint: Remember, Do it in one sentence.

CodePudding user response:

I would go with:

a = ["a", nil, "b", "c", nil]
b = ["d", nil, "e", "f"]

a.compact.zip(b.compact.reverse).map(&:join)
#=> ["af", "be", "cd"]

CodePudding user response:

a = ["a", nil, "b", "c", nil]
b = ["d", nil, "e", "f"]

a.compact.map{ |x| [x,b.compact.pop].join }
#=> ["af", "be", "cd"]
  •  Tags:  
  • ruby
  • Related