I have an array of strings:
[
'Alica Brereton,Marijuana,9.18,50',
'David Ernest,Methamphetamine,108.78,5',
'David Ernest,cocaine,80,2',
'Gabriella Hyde,Marijuana,9.18,10',
'Gabriella Hyde,Methamphetamine,108.78,8',
'Joel Forro,ecstasy,19.12,10',
'Joel Forro,heroin,91.16,5',
'William Kotai,ecstasy,19.12,20'
]
and i would like to remove the names from the start of each string so the end result would be:
[ 'Marijuana,9.18,50', 'Methamphetamine,108.78,5', 'cocaine,80,2', 'Marijuana,9.18,10', 'Methamphetamine,108.78,8', '19.12,10', 'heroin,91.16,5', 'ecstasy,19.12,20' ]
this is my existing code:
const fs = require("fs");
const data = fs.readFileSync("data.txt").toString();
const lines = data.split("\n");
let customerKeys = lines[0].replace("customer", "Total Price");
lines.shift();
console.log(customerKeys);
console.log(lines);
let array = lines.filter((str) => {
return str !== "";
});
let arrNoSpaces = array;
arrNoSpaces.sort();
console.log(arrNoSpaces);
let keyValues = (customerKeys[0] += arrNoSpaces[1]);
keyValues += {};
console.log(keyValues);
customerKeys = customerKeys.split(",");
var TotalPrice = customerKeys.shift();
customerKeys.push(TotalPrice);
const customerNames = arrNoSpaces.map((line) => line.match(/\w+ \w+/)?.[0]);