[英]ProcessData Node.js stin/stdout) issues
在理解如何使用hackerrank(node.js)上的ProcessData包裝函數運行代碼時遇到一些麻煩。 似乎我不能在沒有返回〜對stdout無響應〜的情況下,刪除帶有ProcessData包裝器中參數的函數。 如何將它們的輸入(整數字符串)傳遞給函數,並獲得某種響應,以便進行調試? 幫助將不勝感激。 請在下面查看我的功能,編碼環境,輸入和預期輸出。 謝謝!
供參考: https : //www.hackerrank.com/challenges/array-left-rotation
/*
Input Format
The first line contains two space-separated integers
denoting the respective values of (the number of integers)
and (the number of left rotations you must perform).
The second line contains space-separated integers
describing the respective elements of the array's initial state.
*/
/*Environment with my code, below (how do I pass input as an argument to this function??
console.log or return the data, and get a response for debugging?)*/
function processData(input) {
//Enter your code here
var rotate = function(num,turns,ar){
var store = ar.slice(0, turns);
for(var i=0; i<store.length; i++){
ar.shift();
ar.push(store[i]);
}
return ar;
};
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
您需要使用process.stdout.write
。 例如:
function processData(input) {
//Enter your code here
process.stdout.write('5 1 2 3 4');
}
代替使用
讓輸入= 4; // 4是一個整數變量
函數processData(input){
//在輸出整數之前,您需要使用toString()將其轉換為字符串;
process.stdout.write(input.toString().trim());
}
//注意輸出已轉換為字符串
輸出4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.