Module: PrimeProducts::MultiplicationTable

Defined in:
lib/prime_products/multiplication_table.rb

Class Method Summary collapse

Class Method Details

.generate(numbers) ⇒ Object

Generates an ASCII “multiplication table” of the supplied ‘numbers`, suitable for presentation in a shell.

For example, if you pass in ‘[1, 2, 3, 4, 5]`, the result will be:

-------—-----—-+ | * | 1 | 2 | 3 | 4 | 5 | | 1 | 1 | 2 | 3 | 4 | 5 | | 2 | 2 | 4 | 6 | 8 | 10 | | 3 | 3 | 6 | 9 | 12 | 15 | | 4 | 4 | 8 | 12 | 16 | 20 | | 5 | 5 | 10 | 15 | 20 | 25 | -------—-----—-+

 @return [String] the generated table

Parameters:

  • numbers (Array<Integer>, Immutable::SortedSet<Integer>)

    A list of numbers which behaves like an Array, to build a multiplication table of. Using an immutable list is recommended to reduce the chance of accidental mutations.



26
27
28
# File 'lib/prime_products/multiplication_table.rb', line 26

def generate(numbers)
  ::Terminal::Table.new(rows: generate_rows(numbers)).to_s
end