Build a Profile Sentence from CSV
Problem statement
A profile is supplied as one valid CSV record with exactly seven fields in this order: firstname, lastname, email, interests, notes, city, and age.
An unquoted comma separates fields. A field enclosed in double quotes may contain commas. Inside a quoted field, two consecutive double quotes decode to one literal double quote.
Parse the record and return exactly:
<firstname> is <age> years old, lives in <city>, and is interested in <interests>.Use the decoded values without adding or removing characters.
Function
profileSentence(row: String) → StringExamples
Example 1
row = "Ada,Lovelace,ada@example.com,mathematics,first programmer,London,36"return = "Ada is 36 years old, lives in London, and is interested in mathematics."No field is quoted, so the six commas separate the seven fields directly.
Example 2
row = "Ada,Lovelace,ada@example.com,\"math, poetry\",first programmer,London,36"return = "Ada is 36 years old, lives in London, and is interested in math, poetry."The comma inside the quoted interests field is data rather than a delimiter.
Example 3
row = "Grace,Hopper,grace@example.com,\"compilers and \"\"debugging\"\"\",navy pioneer,Arlington,85"return = "Grace is 85 years old, lives in Arlington, and is interested in compilers and \"debugging\"."Each doubled quote inside the quoted interests field decodes to one literal quote.
Constraints
7 <= row.length <= 10^5.rowis one valid single-line CSV record with exactly seven non-empty fields.- No whitespace appears outside a quoted field.
- Double quotes appear only as the delimiters of a quoted field or as doubled quote escapes inside one.
- The decoded
firstname,interests,city, andagefields are non-empty.