Skip to content

Commit

Permalink
Added logic for issue the-vampiire#1
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshitaDPoojary committed Oct 13, 2019
1 parent dfcfce8 commit 2382468
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions javascript/beginner/sum-of-all-numbers_hp250497.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const readline = require("readline");

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

const sum_all=(arr)=>{
try{
let i,sum=0;
let min=Math.min(...arr);
let max=Math.max(...arr);
for(i=min;i<=max;i++){
sum+=i;
}
return sum;
}
catch(err){
return(err);
}

}

function question(theQuestion) {
return new Promise(resolve => rl.question(theQuestion, answ => resolve(parseInt(answ))))
}

(async ()=>{
try{
var arr=[];
arr.push(await question("Enter 1st number "));
arr.push(await question("Enter 2nd number "));

console.log("Sum of the array is: "+sum_all(arr));
process.exit();
}
catch(err){
console.log(err)
process.exit(1);
}


})();

0 comments on commit 2382468

Please sign in to comment.