// S列番の列車からDやMの列車を検索する
export const searchSpecialTrain = (trainNum: string, trainList: any[]) => {
  const searchBase = trainNum.replace("S", "").replace("X", "");
  const search = (text: string) => {
    const TD = trainList[searchBase + text];
    if (TD) {
      return true;
    }
    return false;
  };
  const returnBase = [];
  if (search("D")) returnBase.push(searchBase + "D");
  if (search("M")) returnBase.push(searchBase + "M");

  //増結いしづちの場合
  const baseStr = trainNum
    .replace("D", "")
    .replace("M", "")
    .replace("S", "")
    .replace("X", "");
  const baseNum = parseInt(baseStr);
  if (9000 < baseNum && baseNum < 9047) {
    //いしづちの1001M-1046Mが9000番台になっている場合に発動
    const TD = trainList[`${baseNum - 8000}M`];
    if (TD) returnBase.push(`${baseNum - 8000}M`);
  }
  return returnBase;
};
