I'm trying to solve a simple warm up problem in an online coding environment.
The problem is to find the cumulative sum of an array which will be entered through stdin. Here's the provided code.
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var n = parseInt(readLine());
arr = readLine().split(' ');
arr = arr.map(Number);
}
Here's the code I've added.
var count = 0;
for(i= 0; i<n; i++){
arr[i]+= count;
}
return count;
It's not providing any output on the stdout.
My question is two-pronged.
One, what am I doing wrong here?
Two, can someone help me understand the provided code.
Particularly this line of code doesn't make sense, `arr = arr.map(Number);
`