brain/src/dev/ruby/arrays.md

22 lines
323 B
Markdown
Raw Permalink Normal View History

2020-04-17 12:37:11 +00:00
# Playing with arrays
## Check if all array elements are equals
2019-12-11 16:23:15 +00:00
```ruby
arr = [0, 0, 0, 0, 0, 0, 0]
puts true if arr.uniq.length == 1
```
2020-04-17 12:37:11 +00:00
## Array includes a sub array
```ruby
(subarray & array) == array
```
2023-07-16 13:11:53 +00:00
## Compute values occurences
```ruby
[1, 1, 2, 3, 4, 5, 5, 5, 5].tally
=> {1=>2, 2=>1, 3=>1, 4=>1, 5=>4}
```