0

Here is my code:

if (5 > 2 || 6 > 2 || 7 > 2) {
    console.log("Two is small");
} else {
    console.log("Two is big");
}

Is there a way to shorten it? I am looking for something like this (the code below doesn't work):

if (5, 6, 7 > 2) {
    console.log("Two is small");
else {
    console.log("Two is big");
}
Alex
  • 23
  • 1
  • 5
  • Well, the question here is about shortening multiple ||'s, the expressions being ||'d don't necessarily have to be value comparisons – Joey Oct 14 '17 at 23:51
  • The linked question is about comparing with equality. This one--at least in the sample code--is not just equality, which changes the options other than "just list them all out". – DocMax Oct 14 '17 at 23:54
  • 1
    OP, if you want to check if a list of values are all greater than some other value, you can use `Math.min`, e.g. `if (Math.min(5, 6, 7) > 2) {//do stuff}` – Joey Oct 14 '17 at 23:59

0 Answers0