I am practicing reading files in Node.js and I have a problem, since the input is a .txt file and I read it and return its content to be able to work with it.
What this exercise is about is that I must return the name and the times it is repeated with another name on the day and the same time
The input or content inside the .txt is as follows
RENE=MO10:00-12:00,TU10:00-12:00,TH01:00-03:00,SA14:00-18:00,SU20:00-21:00
ASTRID=MO10:00-12:00,TH12:00-14:00,SU20:00-21:00
ANDRES=MO10:00-12:00,TH12:00-14:00,SU20:00-21:00
And the output I expect is the following
ASTRID-RENE: 2
ASTRID-ANDRES: 3
RENE-ANDRES: 2
And the problem I currently have is that I don't know how to return the expected output
This is my javascript code
const employeesData = data();
const employees = employeesData.split(/\r?\n|\r|\n/g);
const employeesSchedule = employees.map((employee) => {
const [name, schedule] = employee.split('=');
return { name, schedule };
});
const employeesScheduleDays = employeesSchedule.map((employee) => {
const { name, schedule } = employee;
const days = schedule.split(',').map((day) => day.substring(0, 2));
const hours = schedule.split(',').map((day) => day.substring(2));
return { name, days, hours };
});
console.log(employeesScheduleDays);
And the console.log that I get is the following and until there I was able to develop so I need your help
[
{
name: 'RENE',
days: [ 'MO', 'TU', 'TH', 'SA', 'SU' ],
hours: [
'10:00-12:00',
'10:00-12:00',
'01:00-03:00',
'14:00-18:00',
'20:00-21:00'
]
},
{
name: 'ASTRID',
days: [ 'MO', 'TH', 'SU' ],
hours: [ '10:00-12:00', '12:00-14:00', '20:00-21:00' ]
},
{
name: 'ANDRES',
days: [ 'MO', 'TH', 'SU' ],
hours: [ '10:00-12:00', '12:00-14:00', '20:00-21:00' ]
},
{
name: 'DAVID',
days: [ 'MO', 'TU', 'TH', 'SA', 'SU' ],
hours: [
'10:15-12:00',
'10:00-12:00',
'13:00-13:15',
'14:00-18:00',
'20:00-21:00'
]
},
{
name: 'MARIA',
days: [ 'MO', 'TH', 'SU' ],
hours: [ '10:00-12:00', '12:00-14:00', '20:00-21:00' ]
},
{
name: 'FERNANDA',
days: [ 'MO', 'TH', 'SU' ],
hours: [ '10:00-12:00', '12:00-14:00', '20:00-21:00' ]
}
]