cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Expression Library

shubhisharma
New Contributor

Hello All,

If I have an expression library, having content:

{
FindObjectID:x => (
(x == โ€˜OBJ1โ€™ ? โ€˜OBJ2โ€™ :
(x == โ€˜OBJ3โ€™ ? โ€˜OBJ4โ€™ :
(x == โ€˜OBJ5โ€™ ? โ€˜OBJ6โ€™ :
(x == โ€˜OBJ7โ€™ ? โ€˜OBJ8โ€™ :
(x == โ€˜OBJ9โ€™ ? โ€˜OBJ10โ€™ :
(x == โ€˜OBJ11โ€™ ? โ€˜OBJ12โ€™ :
(x == โ€˜OBJ13โ€™ ? โ€˜OBJ14โ€™ :
(x == โ€˜OBJ15โ€™ ? โ€˜OBJ16โ€™ :
(x == โ€˜OBJ17โ€™ ? โ€˜OBJ18โ€™ :
โ€˜UNKNOWNโ€™))))))))))
}

Is there any way to simplify this huge expression?

3 REPLIES 3

nganapathiraju
Former Employee

What are these OBJ1 โ€ฆ OBJ8 etc?

Are you more looking to have dynamically evaluate the number of ternary operations here?

tstack
Former Employee

Since your conditions are simple string comparisons, I would suggest using an Object Literal to store the values for each key and then using the get() method to do the lookup:

{
    objs: {
        OBJ1: 'OBJ2',
        OBJ3: 'OBJ4',
        OBJ5: 'OBJ6',
        OBJ7: 'OBJ8',
    },
    FindObjectID: x => this.objs.get(x, 'UNKNOWN')
}

aleung
Contributor III

you can also consider using the conditional snap which would make this easier to maintain / understand.