Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic for Sum of All Numbers #144

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}


})();