forked from WildCodeSchool/js-katas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
censorship.js
73 lines (62 loc) · 1.7 KB
/
censorship.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
/*
Create a function `censor` which takes an array of sentences and a forbidden word as argument, then returns the array with the word censored.
A censored word is replaced with asterisks, example: "tacos" -> "*****".
Only a full word should be censored.
sentences: [
"I love the smell of tacos in the morning.",
"Where is my umbrella?",
"The test is not a diagnosis of the disease psittacosis.",
"Eat tacos every day."
]
forbidden word: "tacos"
result: [
"I love the smell of ***** in the morning.",
"Where is my umbrella?",
"The test is not a diagnosis of the disease psittacosis.",
"Eat ***** every day."
]
You can't use a loop!
Don't mutate the parameter.
*/
// TODO add your code here
// Begin of tests
const assert = require("assert");
assert.strictEqual(typeof censor, "function");
assert.strictEqual(censor.length, 2);
assert.strictEqual(
censor.toString().includes("for "),
false,
"don't use a loop"
);
assert.strictEqual(
censor.toString().includes("while "),
false,
"don't use a loop"
);
assert.deepStrictEqual(censor([], "test"), []);
assert.deepStrictEqual(censor(["schnibble"], "schnibble"), ["*********"]);
assert.deepStrictEqual(
censor(
[
"I love the smell of tacos in the morning.",
"Where is my umbrella?",
"The test is not a diagnosis of the disease psittacosis.",
"Eat tacos every day.",
],
"tacos"
),
[
"I love the smell of ***** in the morning.",
"Where is my umbrella?",
"The test is not a diagnosis of the disease psittacosis.",
"Eat ***** every day.",
]
);
let test = ["this test is awesome"];
censor(test);
assert.deepStrictEqual(
test,
["this test is awesome"],
"don't mutate the parameter"
);
// End of tests