Build a Multiplication Table Generator in Ruby

0
713

This coding exercise will test your ability to work with various data structures while performing mathematical calculations as you build a dynamic multiplication table generator in Ruby.

Summary

Build a program that dynamically generates a hash based multiplication table in Ruby.

Exercise File

Code File

Exercise Description

In order to pass this exercise you’ll need to build a method that returns a hash based multiplication table, where the key is the base number, and the value are the products of the key and the numbers 1 through 10.

Example

multiplication_table 3

{
  1=>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  2=>[2, 4, 6, 8, 10, 12, 14, 16,18, 20],
  3=>[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
}

Real World Usage

This exercise combines a number of key programming concepts, such as:

  • Working with hashes
  • Performing mathematical equations on collections of data
  • Dynamically generating arrays, filling them with data, and then clearing elements

These features are common in a large number of applications. Additionally, this is a popular coding interview question.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here