Challenge

Problem

Documentation is critical in software development, and markdown is the universal format for READMEs, wikis, and documentation sites. This drill teaches you to read CSV data and transform it into properly formatted markdown tables with alignment, padding, and separators. You'll learn markdown table syntax, dynamic column width calculation, string alignment techniques, and text formatting—skills essential for generating documentation, reports, and developer tools.

Difficulty: Beginner

Instructions

  1. Read CSV file with headers
  2. Calculate the maximum width needed for each column (including header)
  3. Generate markdown table with:
    • Header row with column names
    • Separator row with dashes (e.g., | --- | --- |)
    • Data rows with values
  4. Pad all cells to their column's maximum width
  5. Left-align text columns, right-align number columns
  6. Write output to output.md
  7. Print confirmation: 'Markdown table generated: X rows, Y columns'

Files

Editable
Read-only

Hints

Hint 1

CSV.read(file) returns array of arrays (rows)

Hint 2

First row is headers: data[0], remaining rows: data[1..]

Hint 3

Calculate max width: array.map(&:length).max

Hint 4

Use map.with_index to iterate with column index

Hint 5

string.ljust(width) pads right, string.rjust(width) pads left

Hint 6

Check if numeric: string.match?(/^\d+\.?\d*$/)

Hint 7

Join array with separator: array.join(' | ')

Hint 8

File.write(filename, content) writes string to file

Provided Files (Read-only)

1. Employee data table

Input:
generate_markdown_table('data.csv', 'output.md')
Expected Output:
Markdown table generated: 4 rows, 4 columns

2. Product inventory

Input:
generate_markdown_table('data.csv', 'output.md')
Expected Output:
Markdown table generated: 3 rows, 3 columns

3. Mixed data types

Input:
generate_markdown_table('data.csv', 'output.md')
Expected Output:
Markdown table generated: 3 rows, 4 columns
+ 2 hidden test cases