Script – 21-30 Jan 20

hey guys I'm not sure if I'm the one that do not understand this exercise properly but here it goes see image files From the input format, I understand that there would be multiple lines of input to pass to the function. I am not sure how that's suppose to go as the Function Description says int n: an integer. This has me really confused
UU
Unknown User819d ago
S
Script818d ago
Ohhhhh So all I need to do is write code for one integer n?
UU
Unknown User818d ago
S
Script818d ago
'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

function readLine() {
return inputString[currentLine++];
}

/*
* Complete the 'flippingBits' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER n as parameter.
*/

function flippingBits(n) {
return parseInt((~n >>> 0).toString(2), 2);
}

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const q = parseInt(readLine().trim(), 10);

for (let qItr = 0; qItr < q; qItr++) {
const n = parseInt(readLine().trim(), 10);

const result = flippingBits(n);

ws.write(result + '\n');
}

ws.end();
}
'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

function readLine() {
return inputString[currentLine++];
}

/*
* Complete the 'flippingBits' function below.
*
* The function is expected to return a LONG_INTEGER.
* The function accepts LONG_INTEGER n as parameter.
*/

function flippingBits(n) {
return parseInt((~n >>> 0).toString(2), 2);
}

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const q = parseInt(readLine().trim(), 10);

for (let qItr = 0; qItr < q; qItr++) {
const n = parseInt(readLine().trim(), 10);

const result = flippingBits(n);

ws.write(result + '\n');
}

ws.end();
}
UU
Unknown User817d ago