Powers Of 2 Range Enumerable Mixin Assignment

From CSE425S Wiki
Revision as of 17:15, 11 April 2022 by Dennis.cosgrove (talk | contribs) (→‎Code To Modify)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In this studio we will evolve our code from our Powers of 2 exercise to leverage class mixins.

Documentation To Invesigate

Enumerable

Implementation To Investigate (If Interested)

enum.c

Code To Modify

Add

include Enumerable

to your PowersOfTwoRange class definition.

Client

file to run: src/main/ruby/powers_of_two_range_enumerable_mixin_client/powers_of_two_range_enumerable_mixin_client.rb Ruby logo.svg

map example

texts = exclusive_powers_of_two.map do |value|
  "*** #{value} ***"
end
p texts

should output:

["*** 1 ***", "*** 2 ***", "*** 4 ***", "*** 8 ***", "*** 16 ***", "*** 32 ***", "*** 64 ***", "*** 128 ***", "*** 256 ***"]

select example

perfect_squares = exclusive_powers_of_two.select do |value|
  square_root = Math.sqrt(value)
  square_root == square_root.to_i
end
p perfect_squares

should output

[1, 4, 16, 64, 256]

Unit Test

file: src/test/ruby/powers_of_two_range_enumerable_mixin/powers_of_two_range_enumerable_mixin.rb Ruby logo.svg UnitTest

note: ensure that you have removed all printing to receive credit for any assignment.