Searching for the correct key in the object that corresponds to the value "1".
The function currently outputs undefined, which is the intended behavior.
input : deliveryIds: [5,4,5,3,3]
output: 4
This code snippet aims to find the missing quad by iterating through the Object.
I would greatly appreciate any assistance on what modifications need to be made.
function findMissingQuad(deliveryIds: number[]) {
const idsToOccurrences = {};
deliveryIds.forEach(id => {
if (idsToOccurrences[id]) {
idsToOccurrences[id]++;
} else {
idsToOccurrences[id] = 1 || [];
}
});
return Object.keys(idsToOccurrences).forEach(id => {
if (idsToOccurrences[id] === 1) {
return id;
}
});
}