Skip to content

Instantly share code, notes, and snippets.

View whiz25's full-sized avatar

Afani Martin whiz25

View GitHub Profile
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
- [ ] bubble_sort_by method is implemented and working (Screenshot from Odin)
- [ ] sorts an array of numbers in increasing order
```ruby
unsorted = (1..10).to_a.reverse!
bubble_sort(unsorted) == unsorted.sort # should return true
```
- [ ] sorts an array by accepting a block
```ruby
unsorted = %w[hi hello hey]
bubble_sort_by(unsorted) { |left, right| left.length - right.length } == %w[hi hey hello] # should return true
- [ ] should be identical and returns the same thing as ruby's [`map`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-map). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_map.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] returns a new array with the results of running block once for every element in enum.
```ruby
array = Array.new(100){rand(0...9)}
array.my_map(&block) == array.map(&block) # should return true
```
- [ ] returns an Enumerator if no block is given
```ruby
array.my_map == Enumerator # should return true
```
- [ ] 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
```
- [ ] should be identical and returns the same thing as ruby's [`inject`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-inject). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_inject.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] when a symbol is specified combines each element of the collection by applying the symbol as a named method
```ruby
array = Array.new(100) { rand(0...9) }
array.my_inject(:+) == array.inject(:+) # should true
```
- [ ] combines all elements of enum by applying a binary operation, specified by a block
```ruby
operation = proc { |sum, n| sum + n }
search = proc { |memo, word| memo.length > word.length ? memo : word }
- [ ] should be identical and returns the same thing as ruby's [`none?`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-none-3F). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_none.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] when a class is passed as an argument returns true if none of the collection is a member of such class
```ruby
array = Array.new(100) { rand(0...9) }
array.my_none?(String) == true #true
```
- [ ] when a pattern other than Regex or a Class is given returns true only if none of the collection matches the pattern
```ruby
words = %w[dog door rod blade]
words.my_none?(5) == words.none?(5) #true
- [ ] should be identical and returns the same thing as ruby's [`any?`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-any-3F). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_any.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] when no block or argument is given returns true if at least one of the collection is not false or nil
```ruby
true_array = [nil, false, true, []]
true_array.my_any? == true_array.any? #true
```
- [ ] when a class is passed as an argument returns true if at least one of the collection is a member of such class
```ruby
words = %w[dog door rod blade]
words.my_any?(Integer) == words.any?(Integer) #true
- [ ] should be identical and returns the same thing as ruby's [`all?`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-all-3F). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_all.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] when no block or argument is given returns true when none of the collection members are false or nil
```ruby
true_array = [1, true, 'hi', []]
false_array = [1, false, 'hi', []]
true_array.my_all? == true_array.all? # should return true
```
- [ ] when a class is passed as an argument returns true if all of the collection is a member of such class
```ruby
array = Array.new(100){rand(0...9)}
- [ ] should be identical and returns the same thing as ruby's [`select`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-select). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_select.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] returns an enumerator if no block is given
```ruby
array = Array.new(100){rand(0...9)}
array.my_select == Enumerator #true
```
- [ ] returns an array containing all elements of enum for which the given block returns a true value
```ruby
array = Array.new(100){rand(0...9)}
array.my_select(&block) == array.select(&block)
- [ ] should be identical and returns the same thing as ruby's [`each_with_index`](https://ruby-doc.org/core-2.6.4/Enumerable.html#method-i-each_with_index). ([Screenshot](https://gitlab.com/microverse/guides/projects/requirements_screenshots/raw/master/images/ruby/advanced_building_blocks_enumerable/my_each_with_index.png) from [Odin](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks#assignment-2))
- [ ] calls the given block once for each element in self
```ruby
array = Array.new(100){rand(0...9)}
my_each_output = ''
block = proc { |num, idx| my_each_output += "Num: #{num}, idx: #{idx}\n" }
array.each_with_index(&block)
each_output = my_each_output.dup
my_each_output = ''
array.my_each_with_index(&block)