Trying to find the key in the object that maps to the value "1".
As it stands the function returns undefined.
This is the expected behavior.
input : deliveryIds: [5,4,5,3,3]
output: 4
This is the code that iterates through the Object searching for a key that maps to "1".
Any help on what i need to change is much appreciated.
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;
}
});
}