competitive coding nodejs

Solutions on MaxInterview for competitive coding nodejs by the best coders in the world

showing results for - "competitive coding nodejs"
Hanna
07 Apr 2016
1/*
2Sample addition code
3Test cases file
4
52
62 
710 20
83
910 20 30      
10 */
11
12//Driver code
13'use strict';
14process.stdin.resume();
15process.stdin.setEncoding('utf8');
16let inputString = '';
17let currentLine = 0;
18
19process.stdin.on('data', inputStdin=>{
20    inputString += inputStdin;
21})
22
23process.stdin.on('end', ()=>{
24    inputString = inputString.trim().split("\n").map(string => {
25        return string.trim();
26    })    
27    main();
28})
29
30function readline() {
31    return inputString[currentLine++];
32}
33
34function main() {
35    let t = parseInt(readline());
36    for(let i=0;i<t;i++) {
37        let n = parseInt(readline());
38        let arr = new Array(n);
39        let input_arr = readline().split(" ").map(x=> parseInt(x));
40        for(let j=0;j<n;j++) {
41            arr[j] = input_arr[j];
42        }
43        let sol = solution(arr);
44        console.log(sol);
45    }
46}
47
48//solution start here
49function solution(arr) {
50    let result = 0;
51    for(let i=0;i<arr.length;i++) {
52        result += arr[i];
53    }
54    return result;
55}