ruby-uebungen/Assignment_028/solution/readme.md

12 lines
543 B
Markdown
Raw Normal View History

2023-05-23 09:19:31 +02:00
# Lösung: Map und Reduce
<div style="border: 1px solid grey;"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>
```ruby
def char_count(array)
counts = array.map { |e| e.length }
counts.reduce(:+)
end
array = %w{ Free Kevin Mitnick }
puts char_count(array)
```