比較三元組 - 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' ]
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP