-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.ts
More file actions
33 lines (26 loc) · 774 Bytes
/
Copy pathfunction.ts
File metadata and controls
33 lines (26 loc) · 774 Bytes
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
/*function count(value) {
let length:number = value.length;
console.log(value + " contains " + length + " characters");
}
console.log(count("Hello World"));
function countWithoutSpace(value) {
let length: number = value.replace(/\s/g, "").length;
console.log(value + " contains " + length + " characters");
}
console.log(countWithoutSpace("Hello World"));*/
function count(value: string, spaces?: boolean): number {
let length: number;
if(spaces == false)
{
length = value.replace(/\s/g, "").length;
}
else
{
length = value.length;
}
return length;
}
let myCount1: number = count("Hello World");
console.log(myCount1);
let myCount2: number = count("Hello World", false);
console.log(myCount2);