-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample1.js
More file actions
31 lines (25 loc) · 749 Bytes
/
sample1.js
File metadata and controls
31 lines (25 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function generateRandomArray(length, min, max) {
const randomArray = [];
for (let i = 0; i < length; i++) {
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
randomArray.push(randomNumber);
}
return randomArray;
}
function calculateSum(array) {
let sum = 0;
for (let num of array) {
sum += num;
}
return sum;
}
function main() {
const arrayLength = 100;
const minValue = 1;
const maxValue = 1000;
const randomNumbers = generateRandomArray(arrayLength, minValue, maxValue);
console.log("Randomly Generated Array:", randomNumbers);
const sum = calculateSum(randomNumbers);
console.log("Sum of the Array:", sum);
}
main();