Skip to content

Instantly share code, notes, and snippets.

@onosendi
Last active May 19, 2023 13:30
Show Gist options
  • Save onosendi/71a71a3f1dcf2bceb72bc9a377175705 to your computer and use it in GitHub Desktop.
Save onosendi/71a71a3f1dcf2bceb72bc9a377175705 to your computer and use it in GitHub Desktop.
const xs = [
{
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Kayla', ring_time: 1, queue_id: 1, talk_time: 1,
},
{
agent: 'Jon', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Myke', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Dan', ring_time: 1, queue_id: 1, talk_time: 0,
},
];
function getMissedTransferLeg(legs) {
const i = legs.findIndex((o) => o.talk_time > 0);
const res = legs
.slice(i + 1)
.filter((o) => o.agent && o.ring_time > 0 && o.talk_time === 0);
return i === -1 || !res.length ? {} : res.at(-1);
}
console.log(getMissedTransferLeg(xs));
// { agent: 'Dan', ring_time: 1, queue_id: 1, talk_time: 0 }
console.log(getMissedTransferLeg(xs.slice(3)));
// {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment