Powers Of 2 Range Enumerable Mixin Assignment
Jump to navigation
Jump to search
In this studio we will evolve our code from our Powers of 2 exercise to leverage class mixins.
Contents
Documentation To Invesigate
Implementation To Investigate (If Interested)
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 |
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 | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.