'Which would be faster out of compact vs reduce to remove nil elements from an array?
Say you have an array in ruby and you want to remove all the nil elements, typically you would use compact, but could having a reducer that looks like .reduce([]) { |x, i| x<<i unless i.nil?; x } do the same thing faster?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
