Skip to content

Instantly share code, notes, and snippets.

@whiz25
Last active May 6, 2020 16:24
Show Gist options
  • Save whiz25/d8275b72f3ff965cd8d5b81d9c70ca71 to your computer and use it in GitHub Desktop.
Save whiz25/d8275b72f3ff965cd8d5b81d9c70ca71 to your computer and use it in GitHub Desktop.
- [ ] should be identical and returns the same thing as ruby's [`count`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-count). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_count.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] returns the number of items in enum through enumeration
```ruby
array = Array.new(100){rand(0...9)}
array.my_count == array.count # should return true
```
- [ ] counts the number of items in enum that are equal to item if an argument is given
```ruby
array.my_count(0) == array.count(0) # should return true
```
- [ ] counts the number of elements yielding a true value if a block is given
```ruby
array.my_count(&block) == array.count(&block) # should return true
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment