aboutsummaryrefslogtreecommitdiff
path: root/challenge-280/zapwai/javascript/ch-2.js
blob: e3a17ec1f181f471f10d0449e484db303dcf88b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let mystr = "p|*e*rl|w**e|*ekly|";
proc(mystr);
mystr = "perl";
proc(mystr);
mystr = "th|ewe|e**|k|l***ych|alleng|e";
proc(mystr);
function proc(mystr) {
    console.log("Input:", mystr);
    let cnt = 0;
    let words = mystr.split('|');
    for (let i = 0; i < words.length; i++) {
	if (i % 2 == 0) {
	    for (let l of words[i].split("")) {
		if (l == "*") {
		    cnt += 1;
		}
	    }
	}
    }
    console.log("Output:", cnt);
}