'I have this fizzbuzz problem and I really don't know how to solve it Can somebody help me?
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.
Solution 1:[1]
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"]
Solution 2:[2]
a = ["a", nil, "b", "c", nil]
b = ["d", nil, "e", "f"]
a.compact.map{ |x| [x,b.compact.pop].join }
#=> ["af", "be", "cd"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | spickermann |
| Solution 2 | namtax |
