Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
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!

For reference: 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);
});
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need use process.stdout.write. For example:

function processData(input) {
    //Enter your code here
    process.stdout.write('5 1 2 3 4');
} 
over 4 years ago · Santiago Trujillo Relatório

0

instead use
let input = 4; //4 is an integer variable

function processData(input) {

//before outputing the integre you need to convert it to string using toString();

process.stdout.write(input.toString().trim());

}


//Note the output is converted to string
Output: 4

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda