Skip to content

Instantly share code, notes, and snippets.

@srph
Created July 22, 2020 10:22
Show Gist options
  • Select an option

  • Save srph/63983f309ba8158e0e9926d7d936f243 to your computer and use it in GitHub Desktop.

Select an option

Save srph/63983f309ba8158e0e9926d7d936f243 to your computer and use it in GitHub Desktop.
JS: Get the prior status of the list based on the order of the provided statuses.
/**
* Get the prior status of the list based on the order of the provided statuses.
*
* @example
* getPriorStatus([{ status: 'active' }, { status: 'pending' }, { status: 'approved' }], ['approved', 'active', 'declined', 'pending'])
* @returns
* approved
*/
const getPriorStatus = (data, statuses) => {
for (let i = 0; i < statuses.length; i++) {
const status = statuses[i]
if (data.find(item => item.status === status)) {
return status
}
}
return ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment