Saturday 29 April 2017

ProcessData Node.js stin/stdout) issues

Having a bit of trouble understanding how to run my code using a ProcessData wrapping function on hackerrank (node.js). It seems I can't drop a function with the parameters I have in the ProcessData wrapper without getting back ~no response on stdout~. How do I pass their input (a string of integers) in to my function and get a response of some sort so I can debug? Help would definitely be appreciated. Please see my function, the coding environment, the input & expected output below. Thanks!

    /*

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



via jb07

No comments:

Post a Comment