0

Here is the code:

const presets = (buildType === "___PROD___") ?
                        [   "react",
                            "es2015",
                            { "modules" : false }
                        ] : [
                            "react",
                            "es2015"
                        ];

As can be see, the values of react, es2015 are being repeated. Is it possible to not have this repetition in the ternary operator?

Best,

1 Answer 1

2

How about using the spread syntax?

var standardPresets = ['react','es2015'];
const presets = cond ? [ ...standardPresets , {modules: false} ] : [ ...standardPresets ];

Does you have to use a ternary if? Could you just .push into the array when that condition is met?

const standardPresets = ['react','es2015'];
if(cond){ standardPresets.push({modules: false}); }

Personally, I don't think the repetition is too awful as it is.

Sign up to request clarification or add additional context in comments.

1 Comment

Beer o'clock it is :) np. I like your answer though, was thinking of a similar solutions myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.