Skip to main content
πŸ”€ Parsers & Mini-Interpreters

What you're building

A function parseCSV(text) that converts a CSV string into an array of objects, using the first row as headers.

name,age,city
Alice,30,NYC
Bob,25,LA

β†’

[
  { name: "Alice", age: "30", city: "NYC" },
  { name: "Bob",   age: "25", city: "LA"  },
]

CSV is the most common data-exchange format in the real world β€” spreadsheets, bank exports, analytics pipelines. Every data engineer has written one.

Requirements

  • Split text into lines on \n
  • First line is headers; remaining lines are data rows
  • Split each line on "," to get fields (values stay as strings)
  • Skip completely empty lines (trailing newline at EOF, etc.)
  • Return an array of plain objects

Stretch goals

  • Handle quoted fields containing commas: "Smith, John"
  • Trim whitespace from field values
  • Support a custom delimiter (semicolon, tab, etc.)

What this proves

  • String splitting and line handling β€” the bread and butter of data work
  • You can map a header row onto data rows systematically
  • You understand why "just split on commas" breaks for real CSV
⚑ 40 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
single data row
multiple rows
three-column header
trailing newline is ignored

Run your code to check these.