'use strict';

const trim = (s) => s.match(/\W*(.+)\W*/)[1];

const productFromArray = ([name, category, price]) => ({
  name,
  category,
  price,
});

const productsFromCSV = (csv) =>
  csv
    .split('\n')
    .slice(1)
    .map(trim)
    .map((s) => s.split(', '))
    .map(productFromArray);

const productsCSV = `name, category, price
  Klingon Letter Opener, Office Warfare, 19.99
  Backpack of Holding, Travel, 29.99
  Tardis Alarmclock, Merchandise, 15.99`;

const products = productsFromCSV(productsCSV);
console.log(products);
