Skip to content

Instantly share code, notes, and snippets.

@onosendi
Created May 19, 2023 17:10
Show Gist options
  • Save onosendi/6bfad606572c845a405bd9ed208ef2b6 to your computer and use it in GitHub Desktop.
Save onosendi/6bfad606572c845a405bd9ed208ef2b6 to your computer and use it in GitHub Desktop.
const R = require('ramda');
const xs = [
{
agent: 'Kim', ring_time: 1, queue_id: 1, talk_time: 0,
},
{
agent: 'Frank', 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: 0, queue_id: 1, talk_time: 0,
},
{
agent: 'Dan', ring_time: 1, queue_id: 1, talk_time: 0,
},
];
const getMissedTransferLegs = R.ifElse(
R.find((o) => o.agent && o.talk_time > 0),
R.pipe(
R.takeLastWhile((o) => !(o.agent && o.talk_time > 0)),
R.filter((o) => o.agent && o.ring_time > 0 && o.talk_time === 0),
),
R.always([]),
);
console.log(getMissedTransferLegs(xs));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment