forked from the-vampiire/hacktoberithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logic for issue the-vampiire#1
- Loading branch information
1 parent
dfcfce8
commit 2382468
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
})(); |