Created
August 22, 2020 02:06
-
-
Save godie007/9bfce2035dbe069ab3135dad55d720b3 to your computer and use it in GitHub Desktop.
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
eventDevice = [] | |
function callEvent(idDevice, idTable) { | |
if (eventDevice.some(d => d.idDevice === idDevice && d.state === 'A')) { | |
// caso B | |
eventDevice = eventDevice.filter(d => d.idDevice === idDevice).map(m => { | |
m.state = 'B' | |
return m | |
}) | |
} | |
else if (eventDevice.some(d => d.idDevice === idDevice && d.state === 'B')) { | |
// caso C | |
eventDevice = eventDevice.filter(d => d.idDevice !== idDevice) | |
} | |
else { | |
// caso A | |
eventDevice = eventDevice.concat({ idDevice, state: 'A', idTable }) | |
} | |
console.log(JSON.stringify(eventDevice)); | |
} | |
callEvent("111","000") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment