Help us understand the problem. What is going on with this article?

JS の最少記述の検討 with Closure Compiler

More than 1 year has passed since last update.

AND OR 条件をうまくやればもっと綺麗に書けるんだろうなぁと思いつつ頭が足りないので Closure Compiler Service の力を借りる。

JS の処理を取り敢えず minify して条件式に戻す策にて。

三項演算子の訳分からんくなった処理を、取り敢えず処理部分を数字に置き換えてみた。

元々のがこうだとすると

if (1) {
    if (!2 && !3) 4;
    else 5;
} else if (6) 7;
else 5;

こんな感じになる。

1 ? 2 || 3 ? 5 : 4 : 6 ? 7 : 5;

それでも良く分からんので、

適当に Chrome の console にぶち込んで数字の前に ! を付けて分岐を調べつインデントを付けてたら、分岐が大よそ分かった。

1 ?
    2 || 3 ?
        5 :
        4
    :
    6 ?
        7:
        5;

これをまた if 分に戻すと ! が削れて若干シンプルになったので、喜んでコレで終わりに。

if (1) {
    if (2 || 3) 5;
    else 4;
} else if (6) 7;
else 5;
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした