比較三元組 - JavaScript?


為此,你需要使用 if 條件來比較三元組。

假設我們傳遞以下值 -

35, 36, 37, 33, 48, 50

示例

以下是程式碼 -

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));

要執行以上程式,請使用以下命令 -

node fileName.js.

在這裡,我的檔名是 demo242.js。

輸出

輸出如下 -

PS C:\Users\Amit\javascript-code> node demo242.js
[ '1', '1' ]

更新於: 03-10-2020

138 次檢視

開啟你的 職業生涯

完成課程,獲取證書

開始學習
廣告