-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge_13_test.js
More file actions
42 lines (36 loc) · 976 Bytes
/
Copy pathchallenge_13_test.js
File metadata and controls
42 lines (36 loc) · 976 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
33
34
35
36
37
38
39
40
41
42
/*
Challenge 13; REMOVE CHARACTERS
Write a program which removes specific characters from a string.
The first argument is a path to a file.
The file contains the source strings and the characters that need to be scrubbed.
Each source string and characters you need to scrub are delimited by comma.
*/
var expect = require('chai').expect
, d1 = "how are you, abc"
, d2 = "hello world, def"
, e1 = "how re you"
, e2 = "hllo worl"
;
function removeChars(a) {
var s = a.split(",")
, chars = s[1]
, rx, out = ""
, i = 1, j = chars.length
;
while( i < j) {
console.log("len: " + j + ", i: " + i );
rx = new RegExp( chars[i] , 'g');
out = s[0].replace(rx, "");
s[0] = out;
i += 1;
}
return out;
}
describe('removeChars()', function(){
it('should work 1', function(){
expect( removeChars(d1) ).to.be.equal(e1);
});
it('should work 2', function(){
expect( removeChars(d2) ).to.be.equal(e2);
});
});