jason
BAN USERfunction timeLog(entries) {
let timePunches = [];
let numPeopleClockedIn = 0;
//first remap the entries to "clock in" or "clock out" events and add them to the timePunches array
entries.map(entry => {
timePunches.push({name: entry[0], time: entry[1], action: 'in'});
timePunches.push({name: entry[0], time: entry[2], action: 'out'});
});
//sort the timePunches array in order or time
//then increment or decrement the number of people logged in depending on the action
timePunches
.sort((a, b) => a.time - b.time)
.forEach(clock => {
numPeopleClockedIn = clock.action === 'in' ? numPeopleClockedIn+1 : numPeopleClockedIn-1;
console.log({time: clock.time, numPeopleClockedIn});
});
}
timeLog([
['jane', 1.2, 4.5],
['jin', 3.1, 6.7],
['june', 8.9, 10.3]
]);
- jason February 16, 2017