-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCh-3.js
More file actions
executable file
·39 lines (31 loc) · 1.02 KB
/
Ch-3.js
File metadata and controls
executable file
·39 lines (31 loc) · 1.02 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
/*Write a function min that takes two arguments and returns their minimum.*/
function min(a, b) {
if (a < b) {
return a;
} else return b;
}
console.log(min(2,3));
console.log("***End of this solution***");
/* Recursion
Define a recursive function to determine whether a number is even or odd.
*/
function isEven(number) {
if (number === 0) {
return true;
} else if (number === 1) {
return false;
} else return isEven(number-2);
}
console.log(isEven(75));
console.log("***End of this solution***");
/* write a function called countChar that takes a first argument as a string and a second argument that indicates the character that is to be counted for the number of times it appears in the first string argument */
function countChar(str, character) {
var count = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] == character) {
count += 1;
}
} return count;
}
console.log(countChar("AAbbccc", "c" ));
console.log("***End of this solution***");