โ11-17-2017 12:00 AM
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?
โ11-17-2017 02:44 AM
What are these OBJ1 โฆ OBJ8 etc?
Are you more looking to have dynamically evaluate the number of ternary operations here?
โ11-17-2017 03:47 AM
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')
}
โ11-17-2017 04:37 AM
you can also consider using the conditional snap which would make this easier to maintain / understand.