Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

So sánh bộ ba (Compare the Triplets) - JavaScript

So sánh 3 cặp số (a,b,c) vs (d,e,f), đếm số lần a>d, b>e, c>f và ngược lại.

Mã thực hiện

function tripletsSolution(first, second, third, fourth, fifth, sixth) {
  var storedResult = [];
  if (first > fourth || second > fifth || third > sixth) storedResult = storedResult + 1;
  if (first < fourth || second < fifth || third < sixth) storedResult = storedResult + 1;
  return storedResult.split('');
}
console.log(tripletsSolution(35, 36, 37, 33, 48, 50));

Kết quả

[ '1', '1' ]

Lưu ý: Logic gốc có vẻ sai so với bài toán Compare Triplets chuẩn (thường đếm điểm riêng cho Alice và Bob). Code này chỉ trả về mảng ['1','1'].