mercredi 11 août 2021

How to simplify this if statement [closed]

I am currently trying to simplify the following code written in Javascript

let x = 5;
let y = 10;
let z = 19;
let answer;
arrays = ["x", "y", "z"]; 

if("x" in arrays){
      answer = x;           
}

if("x" in arrays && "y" in arrays){
    answer = x + y
}

The code will continue on and on for all the possible combinations of x, y and z. What I want to know is how I can simplify the above block of code and achieve the same result. Thank you.

Aucun commentaire:

Enregistrer un commentaire