我的目標是以更適當的形式重構下面的條件。用更好的東西代替這些條件會很好。如果重構witth包含邏輯
該邏輯的主要思想是這些「ifs」的順序不應該改變。即,如果數組中至少存在一個「j」值,即使存在其他值,也應該返回該值。
var items = [j,a];
if(_.contains(items, "j")) {
return "j";
} else if(_.contains(items, "a")) {
return "a";
} else if(_.contains(items, "l")) {
return "l";
}
return "d";
任何想法將不勝感激。
這可能適合更好在http://codereview.stackexchange.com/ – deltree