Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function to parse a CSV string into an array of objects.

Hard

Problem Statement

Implement a function to parse a CSV string into an array of objects.

Sample Input

"Name,Age,City\nJohn,25,New York\nAlice,30,Los Angeles"

Sample Output

[ { Name: 'John', Age: '25', City: 'New York' },
  { Name: 'Alice', Age: '30', City: 'Los Angeles' } ]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Parse a CSV string into an array of objects function parseCSV(csv) { // Split CSV by newline to get rows // Use the first row as keys for the objects // Map remaining rows to objects with keys and values } console.log(parseCSV("Name,Age,City\nJohn,25,New York\nAlice,30,Los Angeles"));
Log in or sign up to run or submit your code.Log inSign up
Input
"Name,Age,City\nJohn,25,New York\nAlice,30,Los Angeles"
Expected Output
[ { Name: 'John', Age: '25', City: 'New York' },
  { Name: 'Alice', Age: '30', City: 'Los Angeles' } ]