-
Notifications
You must be signed in to change notification settings - Fork 2
/
string_includes.js
38 lines (23 loc) · 944 Bytes
/
string_includes.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
// String.prototype.includes() use cases
/*
YouTube Upload Count
You are given an array of "dates" in the format "Dec 11" and a "month"
in the format "Dec" as arguments. Each "date" represents a "video"
that was uploaded on that day. Return the number of uploads for a given month.
Output:
uploadCount(["Sept 22", "Sept 21", "Oct 15"], "Sept"); // output: 2
uploadCount(["Sept 22", "Sept 21", "Oct 15"], "Oct"); // output: 1
*/
// Solution:
function uploadCount(arrayDates, stringMonth){
let totalUploads = 0;
for(let i = 0; i < arrayDates.length; i++){
if(arrayDates[i].includes(stringMonth)){ // includes()
totalUploads++;
}
}
return console.log(totalUploads);
}
uploadCount(["Sept 22", "Sept 21", "Oct 15"], "Sept"); // output: 2
uploadCount(["Sept 22", "Sept 21", "Oct 15"], "Oct"); // output: 1
// -------------------------------------------------------------------------