-
Notifications
You must be signed in to change notification settings - Fork 56
/
subject.js
74 lines (58 loc) · 1.47 KB
/
subject.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//not covered according to homework description
//mising from my implementation
var fs = require("fs");
function inc(p, q){
if(q ==undefined) q =1; //not covered
if( p < 0 ) //not covered
{
p = -p; //not covered
}
return p + q/q;
}
function fileTest(dir, filePath)
{
if (!fs.existsSync(dir)){
return false;
}
if( fs.existsSync(filePath ))
{
var buf = fs.readFileSync(filePath, "utf8");
if( buf.length > 0 ) //not covered
{
return true;
}
return false; //not covered //missing
}
}
function normalize(phoneNumber) {
return phoneNumber.replace(
/^[\+\d{1,3}\-\s]*\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,
"$1$2$3"
);
}
function format(phoneNumber, formatString, options)
{
// Normalize the phone number first unless not asked to do so in the options
if (!options || !options.normalize) { //not covered
phoneNumber = normalize(phoneNumber)
};
for ( var i = 0, l = phoneNumber.length; i < l; i++ ) { //not covered
formatString = formatString.replace("N", phoneNumber[i]); //not covered
}
return formatString;
}
function blackListNumber(phoneNumber)
{
var num = format(phoneNumber, "(NNN) NNN-NNNN");
var area = num.substring(1,4);
if( area == "212" ) //not covered
{
return true; //not covered
}
return false;
}
exports.fileTest = fileTest;
exports.normalize = normalize;
exports.format = format;
exports.inc = inc;
exports.blackListNumber = blackListNumber;