forked from chungl/quizzes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionDefinitions.js
More file actions
77 lines (61 loc) · 2.23 KB
/
functionDefinitions.js
File metadata and controls
77 lines (61 loc) · 2.23 KB
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
74
75
76
77
require("inline-mocha")(module);
const assert = require('assert');
const mockCl = require('./mockCl.js');
const TODO = 'TODO';
// DIRECTIONS: complete the prompts below, replacing TODO with your solution to each prompt:
// Write a function called add which accepts two numbers as arguments and returns their sum.
TODO
// Write a function called concatenateStrings which accepts two strings, joins them together, and returns the joined string.
TODO
// Write a function called shorten that accepts a single string.
// The function should remove all the spaces in the string and return the new string.
// Don't spend too much time on this problem if you get stuck.
TODO
// write a function called greeter that does not take arguments.
// The function should use console.log to print 'hello'.
TODO
// The following tests should pass when you have successfully completed the above prompts:
// There is no need to modify these tests.
describe('add', function() {
it("Should be a function", function() {
assert.equal(typeof(add), 'function');
});
it("should do addition", function() {
assert.equal(add(1, 1), 2);
assert.equal(add(2, 5), 7);
});
});
describe('concatenateStrings', function() {
it("Should be a function", function() {
assert.equal(typeof(concatenateStrings), 'function');
});
it("should combine strings", function() {
assert.equal(concatenateStrings('foo', 'bar'), 'foobar');
assert.equal(concatenateStrings('should not', 'add spaces'), 'should notadd spaces');
});
});
describe('shorten', function() {
it("Should be a function", function() {
assert.equal(typeof(shorten), 'function');
});
it("should remove a single space", function() {
assert.equal(shorten('no space'), 'nospace');
});
it("should remove multiple spaces", function() {
assert.equal(shorten('I am a sentence with six spaces'), 'Iamasentencewithsixspaces');
});
});
describe('greeter', function() {
it("Should be a function", function() {
assert.equal(typeof(greeter), 'function');
});
it("should say hello", function() {
mockCl.start({passThrough: false});
try {
greeter();
} finally {
mockCl.stop();
}
assert(mockCl.stack.includes('hello'));
});
});