function extractUniqueEvents(journal) {
let uniqueEvents = [];
for (let entry of journal) {
for (let event of entry.events) {
if (!uniqueEvents.includes(event)) {
uniqueEvents.push(event);
}
}
}
return uniqueEvents;
}
console.log(extractUniqueEvents(JOURNAL));
In this function, the 'if' condition checks whether an event is already included in the 'uniqueEvents' array. The `!` operator negates the result of includes(), meaning that it adds an event to the list only if it's not already present. When you remove this check from the code, every event gets added to the array even if it's duplicated, resulting in an empty array in the end.
I hope this explanation clarifies your doubt.
JOURNAL