2023-05-25 17:47:19 +02:00
|
|
|
# Lösung: Map und Reduce
|
2023-05-23 09:19:31 +02:00
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
<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>
|
2023-05-23 09:19:31 +02:00
|
|
|
```ruby
|
2023-05-25 17:47:19 +02:00
|
|
|
def char_count(array)
|
|
|
|
counts = array.map { |e| e.length }
|
|
|
|
counts.reduce(:+)
|
2023-05-23 09:19:31 +02:00
|
|
|
end
|
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
array = %w{ Free Kevin Mitnick }
|
|
|
|
puts char_count(array)
|
|
|
|
```
|