Skip to content

Instantly share code, notes, and snippets.

@mjmeilahn
Last active March 17, 2023 15:25
Show Gist options
  • Save mjmeilahn/57e79ac93e18d8ddb3d2ef283e5ebf8d to your computer and use it in GitHub Desktop.
Save mjmeilahn/57e79ac93e18d8ddb3d2ef283e5ebf8d to your computer and use it in GitHub Desktop.
JS: Performance Log Sequence
// Return an array of User IDs that have
// logged the correct actions taken at least once
// in the performance logs with this exact sequence: A => B => C
const logs = [
{ userID: 1, action: 'C' },
{ userID: 2, action: 'B' },
{ userID: 3, action: 'B' },
{ userID: 2, action: 'A' },
{ userID: 2, action: 'B' },
{ userID: 3, action: 'C' },
{ userID: 3, action: 'A' },
{ userID: 1, action: 'A' },
{ userID: 3, action: 'B' },
{ userID: 2, action: 'C' },
{ userID: 1, action: 'B' },
{ userID: 3, action: 'C' },
]
const performaceLogs = arr => {
const users = []
arr.map(log => {
const id = log.userID
const user = arr.filter(i => id === i.userID)
const actions = user.map(u => u.action).join('')
if (actions.includes('ABC') && !users.includes(id)) {
users.push(id)
}
})
return users
}
console.log(performaceLogs(logs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment