Over a million developers have joined DZone.

Sum Values Across An Array

·
Use inject. Good for any cumulative operation.
Returns the sum.


anArray.inject(0) { |s,v| s += v }


Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}