-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmin-max-num.js
More file actions
20 lines (15 loc) · 759 Bytes
/
min-max-num.js
File metadata and controls
20 lines (15 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const input = require("./input");
(async() => {
const numbers = await input("Enter list of numbers separated by comma: ");
const converted_numbers = numbers.split(",").map(item => Number(item.trim()));
// Min and Max variable
min_num = converted_numbers[0]; // Assuming the first index is the smallest
max_num = converted_numbers[0]; // Assuming the first index is the biggest
// Finding both the smallest and biggest number
converted_numbers.forEach((item, index) => {
if (item < min_num) min_num = converted_numbers[index];
if (item > max_num) max_num = converted_numbers[index];
});
// Printing the output
console.log(`Smallest (Min) Number: ${min_num}\nBiggest (Max) Number: ${max_num}`);
})();