Created
July 22, 2020 10:22
-
-
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.
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
| /** | |
| * 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