Skip to content

Commit

Permalink
Pefer .reduce over .inject
Browse files Browse the repository at this point in the history
  • Loading branch information
charlieegan3 committed Oct 27, 2014
1 parent 560cf50 commit 83e4f1f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/descriptive_statistics/sum.rb
Expand Up @@ -3,6 +3,6 @@ def sum(collection = self)
values = Support::convert(collection)
return DescriptiveStatistics.sum_empty_collection_default_value if values.empty?

return values.inject(:+)
return values.reduce(:+)
end
end
2 changes: 1 addition & 1 deletion lib/descriptive_statistics/variance.rb
Expand Up @@ -4,6 +4,6 @@ def variance(collection = self)
return DescriptiveStatistics.variance_empty_collection_default_value if values.empty?

mean = values.mean
values.map { |sample| (mean - sample) ** 2 }.inject(:+) / values.number
values.map { |sample| (mean - sample) ** 2 }.reduce(:+) / values.number
end
end

0 comments on commit 83e4f1f

Please sign in to comment.