teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

OKならtrue、NGならfalseにした

2019/04/02 04:17

投稿

miyabi-sun
miyabi-sun

スコア21473

answer CHANGED
@@ -28,18 +28,18 @@
28
28
  const nameAndCondition = citiesName.split(/(OK|NG)/).slice(0, -1);
29
29
  for (let i = 0; i < nameAndCondition.length; i += 2) {
30
30
  const name = nameAndCondition[i];
31
- const condition = nameAndCondition[i + 1];
31
+ const condition = nameAndCondition[i + 1] === 'OK';
32
32
  // もしNGの都市を捨てるならこの行のコメントアウトを削る
33
- // if (condition === 'NG') continue;
33
+ // if (!condition) continue;
34
34
  result[name] = condition;
35
35
  }
36
36
  cityList.push(result);
37
37
  }
38
38
  console.log(cityList);
39
39
  // [
40
- // {千代田区: "OK", 中央区: "OK", 港区: "OK", 新宿区: "OK", 文京区: "NG"},
40
+ // {千代田区: true, 中央区: true, 港区: true, 新宿区: true, 文京区: false},
41
- // {横浜市: "NG", 川崎市: "OK", 横須賀市: "OK"},
41
+ // {横浜市: false, 川崎市: true, 横須賀市: true},
42
- // {千葉市: "OK", 銚子市: "NG", 市川市: "NG"}
42
+ // {千葉市: true, 銚子市: false, 市川市: false}
43
43
  // ]
44
44
  ```
45
45