Given an array that contains some status string,
I want to validate if the array contains at least one sleeping status and then validate if the rest of the statuses are either ok or sleeping.
So a valid array is ['ok', 'sleeping', 'sleeping', 'ok'] and an invalid array will be something like const states = ['ready', 'working','onBreak','sleeping', 'ok', 'sleeping']
What I have come up with so far is this:
const validArray = ['ok', 'sleeping', 'sleeping', 'ok'];
const isvalid = validArray.some( x => x === 'sleeping')
if(isValid){
const canDoStuff = validArray.some( x => !['ok','sleeping'].includes(x))
if(canDoStuff){
doStuff()
}
}
Ideally, I would like to validate that in a single loop,and not two loops.