DEV Community

Discussion on: 5 Programming Patterns I Like

Collapse
 
qcgm1978 profile image
Youth

You're right. I have found it is exactly easy to understand the ternaries because the priority level is default satisfying what I want it to be. But One loop two arrays I don't agree. I code the following code and it is more elegant:

const validTrolley = result.filter(item => item.inventoryCount && item.putShelvesFlg)
const invalidTrolley = result.filter(item => !(item.inventoryCount && item.putShelvesFlg)).map((item, index) => {
            item.isInvalid = !index;
            return item;
          })