Last active
October 10, 2019 10:20
-
-
Save SoxFace/adfc8bbfda8c4f06a6386a767af8c1d3 to your computer and use it in GitHub Desktop.
Revisions
-
SoxFace revised this gist
Oct 10, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ def example(a) # function a # 1) write the same thing but replace that logic using ruby each method # 2) write the same thing but avoid modifying the array, hint: use map # hint: (0..a).each { |i| ... } and (0..a).map { |i| ... } # https://www.rubyguides.com/2018/10/ruby-map-method/ # 1) using each -
SoxFace revised this gist
Oct 10, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,5 +38,4 @@ def exampleEach(a) (0..a).map { |i| b[i] = i } end -
SoxFace revised this gist
Oct 10, 2019 . 1 changed file with 20 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,18 +13,30 @@ def example(a) # function a # => [0, 1, 2, 3, 4] # 1) write the same thing but replace that logic using ruby each method # 2) write the same thing but avoid modifying the array, hint: use map # hint: (0..a).each { |i| ... } and (0..a).map { |i| ... } # 1) using each def exampleEach(a) b = [] (0..a).each { |i| b[i] = i } return b end # 2) using map def exampleEach(a) b = [] (0..a).map { |i| b[i] = i } return b end -
SoxFace revised this gist
Oct 10, 2019 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,9 @@ def example(a) # function a # => [0, 1, 2, 3, 4] # another way of doing it # again I'm unsure why b.push[i] is assigned to i def examplePush(a) b = [] -
SoxFace created this gist
Oct 10, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ def example(a) # function a b = [] # b is an empty array for i in 0..a # for every (i)ndex in the range 0 to a (or 4 in this example) b[i] = i # not clear how this works. I think it's a shorthand for .push # More importantly, I don't know why you have to assign the position of the index in the array to i end # end of loop return b #return b end # end of function example(4) # calls a, loops, pushes 0, 1, 2, 3, 4 into the array b # => [0, 1, 2, 3, 4] def examplePush(a) b = [] for i in 0..a b.push[i] = i end return b end example(5)