Last active
May 19, 2023 13:30
-
-
Save onosendi/71a71a3f1dcf2bceb72bc9a377175705 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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