Ponchimeow/Practice

黑澀會美眉

Opened this issue · 0 comments

Lidemy OJ, 黑澀會美眉


function pa(arr) {
  let res = [];
  arr.forEach(element => {
    let group = element.split(' ');  // 字串以空白分割
    // 切割後組成 Object 放入 res 陣列中
    res.push({
      "Name1": group[0],
      "Name2": group[1],
      "Rela": group[2]
    });
  });
  let lowest = 0;  // 設最低值的 index 0
  // 逐一比對,若有最小值則以新值取代 lowest
  for (let i = 0; i < res.length; i += 1) {
    if (res[i].Rela < res[lowest].Rela) {
      lowest = i;
    };
  };
  if (res[lowest] >= 0) {
    return `Are you kidding me?`;
  } else {
    return `${res[lowest].Name1} ${res[lowest].Name2}`;
  };
}