-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavascriptarray_02.html
More file actions
69 lines (65 loc) · 2.05 KB
/
Copy pathJavascriptarray_02.html
File metadata and controls
69 lines (65 loc) · 2.05 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<!-- //numbers =[11,22,45,67,'e','m','n','a'];
//Count no of odd nos.
//Count no of Even nos.
//count no of Vowels.
//count no of consonents.
//Eliminate all string data create a numeric array and find out max & min .
//Sum of all numeric elements
//average of all numeric elements.
-->
<script type="text/javascript">
var numbers = [11, 22, 45,67,'e','m','n','a'];
// Count number of odd numbers
var oddCount = 0;
var evenCount = 0;
var vowelCount = 0;
var consonantCount = 0;
var numericArray = [];
for (var i = 0; i < numbers.length; i++) {
if (typeof numbers[i] === 'number') {
if (numbers[i] % 2 === 0) {
evenCount++;
} else {
oddCount++;
}
numericArray.push(numbers[i]);
} else if (typeof numbers[i] === 'string') {
var str = numbers[i].toLowerCase();
for (var j = 0; j < str.length; j++) {
var char = str[j];
if ("aeiou".includes(char)) {
vowelCount++;
} else if (char >= 'a' && char <= 'z') {
consonantCount++;
}
}
}
}
console.log("Odd Numbers Count:", oddCount);
console.log("Even Numbers Count:", evenCount);
console.log("Vowel Count:", vowelCount);
console.log("Consonant Count:", consonantCount);
// Find max and min values in the numeric array
var maxNum = Math.max(...numericArray);
var minNum = Math.min(...numericArray);
console.log("Numeric Array:", numericArray);
console.log("Maximum Number:", maxNum);
console.log("Minimum Number:", minNum);
// Sum and Average of numeric elements
var sum = numericArray.reduce(function (acc, num) {
return acc + num;
}, 0);
var average = sum / numericArray.length;
console.log("Sum of Numeric Elements:", sum);
console.log("Average of Numeric Elements:", average);
</script>
<body>
</body>
</html>