From f89c8f2f362910a9bb42fc62a432609d034f0cf3 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 25 Sep 2019 00:01:56 +0100 Subject: [PATCH 1/8] initial commit --- Enumerable_Methods.rb | 3 +++ README.md | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Enumerable_Methods.rb diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb new file mode 100644 index 0000000..7a0cfcc --- /dev/null +++ b/Enumerable_Methods.rb @@ -0,0 +1,3 @@ +# /usr/bin/ruby +# frozen_string_literal: true + diff --git a/README.md b/README.md index 2b60c5f..f83871f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ -# Enumerable-Methods -Microverse Project On Enumerable Methods +# Project Descriptioon: + +Advanced Building Blocks - Enumerable Methods Using Ruby Language. + +# Contributor(s): + +Kingsley McSimon Ogbonna https://github.com/KingsleyMcSimon @KingsleyMcSimon + +# Link to the project on Github: + +https://github.com/KingsleyMcSimon/Enumerable-Methods + + From 8fd9bee4169f9e1a9fb0ba0bd45f632549e456fe Mon Sep 17 00:00:00 2001 From: Your Date: Mon, 7 Oct 2019 22:31:08 +0100 Subject: [PATCH 2/8] enumerable methods --- Enumerable_Methods.rb | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 7a0cfcc..18e10a8 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -1,3 +1,73 @@ # /usr/bin/ruby # frozen_string_literal: true + + +module Enumerable + + def my_each #This is my_each method + a = 0 + self.size.times do + yield(self[a]) + a += 1 + + end + + self + end + + def my_each_with_index #my_each_with_index + a = 0 + self.size.times do + yield(self[a], a) + a += 1 + end + + self + + end + + def my_select #my_select method + myselect = [] + self.my_each do |b| + if yield (b) + myselect.push (b) + + end + + end + + myselect + + end + + def my_all? #my_all method + myall = [] + output = true + self.my_each do |b| + if yield (b) + myall.push (b) + end + end + if myall.length == self.length + output = true + else + output = false + end + output + end + + def my_any? #my_any? method + output = false + self.my_each do |b| + if yield (b) + output = true + break + + end + + end + output + end + + From d438c1709bbca40df3b2f55d41b1bbce11da3173 Mon Sep 17 00:00:00 2001 From: Your Date: Tue, 8 Oct 2019 00:16:41 +0100 Subject: [PATCH 3/8] more of the methods --- Enumerable_Methods.rb | 77 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 18e10a8..739ca71 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -70,4 +70,79 @@ def my_any? #my_any? method output end - + def my_none? #my_none methods + output = true + self.my_each do |b| + if yield (b) + output = false + break + end + end + output + end + + def my_count parameter = nil #my_count method + mycount = 0 + self.my_each do |b| + if parameter != nil + if parameter == self[b] + mycount += 1 + end + else + if yield (b) + mycount += 1 + self.my_each do |element| + if parameter + if element == parameter + mycount += 1 + end + end + elsif block_given? + mycount += if yield(element) + else + mycount = self.length + end + end + mycount + end + + def my_map #my_map method + mymap = [] + self.my_each do |b| + mymap.push yield(b) + end + mymap + end + + def my_map_again(myproc) #my_mapa_gain method which takes a proc + self.my_each do |b| + mymapagain.push myproc.call(b) + end + mymapagain + end + + def my_map_final myproc = nil #my_map_final method which an either take a proc or a block + mymapfinal = [] + self.my_each do |b| + if myproc == nil + mymapfinal.push yield(b) + else + mymapfinal.push myproc.call(b) + end + end + mymapfinal + end + + def my_inject merit = 0 #my_inject method + myinjet merit + self.my_each do |immediately| + myinject = yield myinject immediately + + end + myinject + end +end + + + + From 0e856fcf574b0b823f4e7d8fa599c2dd87576bfa Mon Sep 17 00:00:00 2001 From: Your Date: Tue, 8 Oct 2019 09:36:31 +0100 Subject: [PATCH 4/8] more enumerable methods solution added --- Enumerable_Methods.rb | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 739ca71..8599dd0 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -141,8 +141,85 @@ def my_inject merit = 0 #my_inject method end myinject end + end +#Testing for my_each method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12] +#arraysofnumbers.my_each do |numbers| + # numbers *= 5 + # print "#{numbers}" +#end + +#Testing for my_each_with_index method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 40] +#arraysofnumbers.my_each_with_index do |value, index| +#puts "arraysofnumbers index #{index} takes the value of #{value}" +#end + +#Testing for my_select method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 50] +#output = arraysofnumbers.my_select do |numbers| numbers % 2 != 0; end +#print output + +#Testing for my_all method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 40] +#output = arraysofnumbers.my_all? do |b| b % 2 == 0; end +#print output + +#Testing for my_any method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 25] +#output = arraysofnumbers.my_any? do |b| b < 3; end +#print output + +#Testing for my_none method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 10] +#output = arraysofnumbers.my_none? do |b| b % 2 == 1; end +#print output + +#Testing for my_count method + +#arraysofnumbers = [2, 5, 8, 10, 20, 15, 25, 15, 8, 4, 6] +#arraysofnumbers = [5, 8, 10, 15, 15, 8, 4, 6, 8, 2, 12, 7, 8, 10] +#output = arraysofnumbers.my_count +#output = arraysofnumbers.my_count (10) +#output = arraysofnumbers () do |numbers| numbers % 2 == 1; end +#output = arraysofnumbers (5) do |numbers|; end +#print output + +#Testing for my_map method + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 20] +#output = arraysofumbers.my_map do |numbers| numbers * 2; end +#print output + +#Testing for my_map_again method (that takes a proc) + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 10, 10] +#myproc = Proc.new do |numbers| numbers * 2; end +#output = arraysofnumbers.my_map_again(myproc) +#print output + +#Testing for my_map_final(3) (that takes either a proc or a block) + +#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 35, 30] +#myproc = Proc.new do |numbers| numbers * 2; end +#output = arraysofnumbers.my_map_final do |numbers| numbers * 3; end +#print output + +#Testing for my_inject method + +#def multiply_els(arraysofnumbers) +#arraysofnumbers.my_inject(1) do |total, numbers|total * numbers; end +#end +#arraysofnumbers = [1, 4, 5, 3, 2] +#puts multiply_els(arraysofnumbers) From 546cf4c356f878bdb84a14c6ff6f1d78e9ad3aec Mon Sep 17 00:00:00 2001 From: Your Date: Tue, 8 Oct 2019 09:41:59 +0100 Subject: [PATCH 5/8] more enumerable info added --- Enumerable_Methods.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 8599dd0..8b0890f 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -145,7 +145,8 @@ def my_inject merit = 0 #my_inject method end -#Testing for my_each method +#Testing for my_each method +#(To test each of these methods, you can take it out of the comment and go ahead with the testing ) #arraysofnumbers = [2, 4, 6, 8, 10, 12] #arraysofnumbers.my_each do |numbers| From f4f21a44a22025cd74d6928fd03c03c7dae8a58c Mon Sep 17 00:00:00 2001 From: Your Date: Tue, 15 Oct 2019 01:31:55 +0100 Subject: [PATCH 6/8] my_inject method updated --- Enumerable_Methods.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 8b0890f..c338b25 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -133,18 +133,23 @@ def my_map_final myproc = nil #my_map_final method which an either take a proc o mymapfinal end - def my_inject merit = 0 #my_inject method - myinjet merit - self.my_each do |immediately| - myinject = yield myinject immediately - - end - myinject + def my_inject #my_inject method + output = nil + my_each = result ? yield (output, b) : self |0| end + output +end + + def multiply_els #multiply_els method + my_inject {|mult, b | mult + b} + end end + + + #Testing for my_each method #(To test each of these methods, you can take it out of the comment and go ahead with the testing ) From 4bd7842cdb3b105352a3670aa39b98c0ae1aa2d2 Mon Sep 17 00:00:00 2001 From: Your Date: Tue, 15 Oct 2019 01:35:14 +0100 Subject: [PATCH 7/8] another changes done done to the my_inject method --- Enumerable_Methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index c338b25..fee0ba6 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -135,7 +135,7 @@ def my_map_final myproc = nil #my_map_final method which an either take a proc o def my_inject #my_inject method output = nil - my_each = result ? yield (output, b) : self |0| + my_each = output ? yield (output, b) : self |0| end output end From 17ef4689d59cd750c7c8ef6cd6e643f751171d8b Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 24 Oct 2019 22:30:56 -0700 Subject: [PATCH 8/8] rubocop and stickler added manually --- .rubocop.yml | 0 .stickler.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .stickler.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..e69de29 diff --git a/.stickler.yml b/.stickler.yml new file mode 100644 index 0000000..e69de29