-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEx5.js
57 lines (43 loc) · 1.33 KB
/
Ex5.js
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
/** Create an arrow function named: countIt that counts the number of integer numbers,
* decimal numbers and strings from an array. The countIt function returns nothing and writes
* output to the terminal. */
const countIntegerNumbers = (array) => {
let count = 0;
for(let i = 0; i < array.length; i++){
if(typeof(array[i]) === "number" && array[i] % 1 === 0){
count++;
}
}
return count;
}
const countStrings = (array) => {
let count = 0;
for(let i = 0; i < array.length; i++){
if(typeof(array[i]) === "string"){
count++;
}
}
return count;
}
const countDecimalNumbers = (array) => {
let count = 0;
for(let i = 0; i < array.length; i++){
if(typeof(array[i]) === "number" && array[i] % 1 !== 0){
count++;
}
}
return count;
}
const countIt = (array) => {
const countOfIntegers = countIntegerNumbers(array);
const countOfStrings = countStrings(array);
const countOfDecimals = countDecimalNumbers(array);
console.log(" Number of Integers: " + countOfIntegers
+ "\n Number of Decimal Numbers:" + countOfDecimals
+ "\n Number of Strings:" + countOfStrings);
}
const main = () => {
let array = ["this", "is", 1, 3, 2.1, "a", "test"];
countIt(array);
}
main();