-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
406 lines (338 loc) · 13.6 KB
/
test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
const assert = require("chai").assert
const algo = require("./problem_set_1")
describe("Testing Algorhthms", () => {
// sortEvenAndOdd()
describe("Return evens and odd numbers in descending order where the evens appear first in the array", () => {
it("Should return [8,6,0,7,5,1]", done => {
const result = algo.sortEvenAndOdd([1,7,5,8,0,6])
assert.sameDeepMembers(result,[8,6,0,7,5,1])
done()
})
it("Should return [2,16,88,11,63,809]", done => {
const result = algo.sortEvenAndOdd([809,63,11,2,16,88])
assert.sameDeepMembers(result,[2,16,88,11,63,809])
done()
})
it("Should return [2000,2012,5100,4323,7877,9093]", done => {
const result = algo.sortEvenAndOdd([5100,9093,4323,2000,2012,7877])
assert.sameDeepMembers(result, [2000,2012,5100,4323,7877,9093])
done()
})
})
// sortMeOneMoreTime()
describe("Return sorted arrays by complete ascending order", () => {
it("Should return [[5, 50], [19, 37], [64, 100]]", done => {
const result = algo.sortMeOneMoreTime([[50,5],[37,19],[100,64]])
assert.sameDeepMembers(result, [[5, 50], [19, 37], [64, 100]])
done()
})
it("Should return [ [1, 12, 48], [1, 18, 34], [3, 39, 99] ]", done => {
const result = algo.sortMeOneMoreTime([[1,34,18], [48,1,12], [99,39,3]])
assert.sameDeepMembers(result, [[1,12,48], [1,18,34],[3,39,99]])
done()
})
it("Should return [ [37], [50], [100] ]", done => {
const result = algo.sortMeOneMoreTime([[50],[37],[100]])
assert.sameDeepMembers(result, [[37],[50],[100]])
done()
})
it("Should return [[ 2, 98, 552, 999, 2344, 8477 ],[ 12, 35, 55, 77, 98, 100 ],[ 34, 64, 552, 2000, 8477, 19837 ]]", done => {
const result = algo.sortMeOneMoreTime([[98, 2344, 2, 999, 8477, 552],[64, 34, 19837, 2000, 8477, 552],[12, 55, 98, 100, 77, 35]])
assert.sameDeepMembers(result,[
[ 2, 98, 552, 999, 2344, 8477 ],
[ 12, 35, 55, 77, 98, 100 ],
[ 34, 64, 552, 2000, 8477, 19837 ] ])
done()
})
it(`Should return ${
[ [ 1, 3, 23, 88 ],
[ 3, 4 ],
[ 3, 11, 58, 123, 657 ],
[ 3, 75, 893 ],
[ 23, 53, 84, 123 ] ]}`, done => {
const result = algo.sortMeOneMoreTime([[75, 893, 3], [4,3],[ 84,23,123,53], [23, 3, 88, 1], [123, 3, 657, 11, 58]])
assert.sameDeepMembers( result,
[ [ 1, 3, 23, 88 ],
[ 3, 4 ],
[ 3, 11, 58, 123, 657 ],
[ 3, 75, 893 ],
[ 23, 53, 84, 123 ] ]
)
done()
})
// ADJUST
it(`Should return ${
[ [ 1, 1, 2, 3, 4 ],
[ 1, 1, 2, 5, 8, 10 ],
[ 1, 1, 2, 8, 9, 100 ] ]
}`, done => {
const result = algo.sortMeOneMoreTime(
[
[1, 2, 10, 1, 5, 8],
[1, 4, 3, 2, 1],
[100, 1, 9, 8, 1, 2]
]
)
assert.sameDeepMembers( result,
[ [ 1, 1, 2, 3, 4 ],
[ 1, 1, 2, 5, 8, 10 ],
[ 1, 1, 2, 8, 9, 100 ] ]
)
done()
})
})
// capitalizeFLetter()
describe("Captalize the first letter in every word as well as lowercase every word", () => {
it("Should Return 'I Like Turtles'", done => {
const result = algo.capitalizeFLetter("i Like tUrTles")
assert.equal(result, "I Like Turtles")
done()
})
it("Should Return 'David Likes To Eat Cookies When Nobody Is Watching'", done => {
const result = algo.capitalizeFLetter("dAviD liKEs TO eaT coOKiEs WhEn nOBoDy iS watChIng")
assert.equal(result, "David Likes To Eat Cookies When Nobody Is Watching")
done()
})
it("Should return You Are The Master At Javascript", done => {
const result = algo.capitalizeFLetter("YoU aRe ThE mAsTeR AT JaVaScRipt")
assert.equal(result, "You Are The Master At Javascript")
done()
})
it("Should return Ieatfoodallday", done => {
const result = algo.capitalizeFLetter("iEaTFooDAllDay")
assert.equal(result,"Ieatfoodallday")
done()
})
})
// removeDups()
describe("Return an array with no duplications in descending order", done => {
it("Should return [33,22,11]", done => {
const result = algo.removeDups([33,22,11])
assert.sameDeepMembers(result, [ 33, 22, 11 ])
done()
})
it('Should return [ 44, 42, 12, 7, 5, 2 ]', done => {
const result = algo.removeDups([44,12,42,44,2,12,42,5,7,5,5])
assert.sameDeepMembers(result, [ 44, 42, 12, 7, 5, 2 ])
done()
})
it("Should return [ 3000, 528, 100, 92, 55, 49, 22, 4, 2, 1, 0 ]", done => {
const result = algo.removeDups([22,55,528,1,528,92,100,100,3000, 2,4,0,4,2, 22,92,49,100, 55])
assert.sameDeepMembers(result, [ 3000, 528, 100, 92, 55, 49, 22, 4, 2, 1, 0 ])
done()
})
it("Should return ['cc','bb','aa']", done => {
const result = algo.removeDups(['aa','aa','bb','bb','cc','cc'])
assert.sameDeepMembers(result, ['cc','bb','aa'])
done()
})
})
// repeatMe()
describe('Return a string that repeats itself on every single character', () => {
it("Should return aabbcc", done => {
const result = algo.repeatMe('abc')
assert.equal(result, 'aabbcc')
done()
})
it("Should return hhEElloo-- '' ffrriieendds ooff tthhee nnoorrtthh", done => {
const result = algo.repeatMe("hEllo- ' friends of the north")
assert.equal(result, "hhEElllloo-- '' ffrriieennddss ooff tthhee nnoorrtthh")
done()
})
it("Should return ' '", done => {
const result = algo.repeatMe(" ")
assert.equal(result, " ")
done()
})
})
// removeChar()
describe("Return string without the character", () => {
it("Should return heo", done => {
const result = algo.removeChar("hello", "ll")
assert.equal(result, 'heo')
done()
})
it("Should return aazzkkrr", done => {
const result = algo.removeChar("aazzTTkkrr", "TT")
assert.equal(result, "aazzkkrr")
done()
})
it("Should return iturtles", done => {
const result = algo.removeChar("iliketurtles", "like")
assert.equal(result, 'iturtles')
done()
})
it("Should return askforjeevsgoogle", done => {
const result = algo.removeChar('askforjeevsgoogle','jeevs')
assert.equal(result, 'askforgoogle')
done()
})
it("Should return yuiiss ", done => {
const result = algo.removeChar('yuiiaass', 'aa')
assert.equal(result, 'yuiiss')
done()
})
it("Should return aazziiqllkn", done => {
const result = algo.removeChar("aazijziiqllkn", 'ij')
assert.equal(result, "aazziiqllkn")
done()
})
it("Should return JamesFranko", done => {
const result = algo.removeChar("JamedesFranko", 'de')
assert.equal(result, "JamesFranko")
done()
})
})
// breakTheCamelsBack()
describe('Return a string that puts a space before a capital letter', () => {
it("Should return hello World", done => {
const result = algo.breakTheCamelsBack('helloWorld')
assert.equal(result, 'hello World')
done()
})
it("Should return pokie Man", done => {
const result = algo.breakTheCamelsBack("pokieMan")
assert.equal(result, "pokie Man")
done()
})
it("Should return i Am Who I Say I Am", done => {
const result = algo.breakTheCamelsBack("iAmWhoISayIAm")
assert.equal(result, "i Am Who I Say I Am")
done()
})
it("Should return this Is Camel Case People", done => {
const result = algo.breakTheCamelsBack('thisIsCamelCasePeople')
assert.equal(result, 'this Is Camel Case People')
done()
})
it('Should return i Like To Go To The Pizza Hut Down The Street Cause...!', done => {
const result = algo.breakTheCamelsBack("iLikeToGoToThePizzaHutDownTheStreetCause")
assert.equal(result, "i Like To Go To The Pizza Hut Down The Street Cause")
done()
})
it("Should return 1155 Jj Abrams Food", done => {
const result = algo.breakTheCamelsBack("1155JjAbramsFood")
assert(result, "1155 Jj Abrams Food")
done()
})
it("Should return game Of Thrones", done => {
const result = algo.breakTheCamelsBack("gameOfThrones")
assert(result, "game Of Thrones")
done()
})
})
// findUnique()
describe('Return the unique number', () => {
it("Should return 4", done => {
const result = algo.findUnique("1 5 7 2")
assert.equal(result, 4)
done()
})
it("Should return 3", done => {
const result = algo.findUnique("766 772 331 678 1001")
assert.equal(result, 3)
done()
})
it("Should return 1", done => {
const result = algo.findUnique("0 939 5 101 3 89")
assert.equal(result, 1)
done()
})
it("Should return 3", (done) => {
const result = algo.findUnique("1 3 2 5 7 9")
assert.equal(result, 3)
done()
})
it("Should return 1", (done) => {
const result = algo.findUnique("2 25 115 55 3123 50909")
assert.equal(result, 1)
done()
})
it("Should return 9", (done) => {
const result = algo.findUnique("397 51 745 879 101 2003 401 313 872 239")
assert.equal(result, 9)
done()
})
it("Should return 5", (done) => {
const result = algo.findUnique("123 321 145 733 986 761 879")
assert.equal(result, 5)
done()
})
})
// spaceNumbers()
describe("Return the people who are still on the ship", () => {
it("People on the ship === 4", done => {
const result = algo.spaceNumbers([ [1,2], [3,4], [77,1] ])
assert.equal(result, 74)
done()
})
it("People on the ship === 30", done => {
const result = algo.spaceNumbers([ [2,4], [20, 8], [13, 9], [5, 14], [6, 9] ])
assert.equal(result, 2)
done()
})
it("People on the ship === 11", done => {
const result = algo.spaceNumbers([ [10, 4], [4, 7], [7, 0], [8, 2], [0, 5] ])
assert.equal(result, 11)
done()
})
it("People on the ship === 5", done => {
const result = algo.spaceNumbers([ [10,0],[3,5],[5,8] ])
assert.equal(result, 5)
done()
})
it("People on the ship === 17", done => {
const result = algo.spaceNumbers([[3,0],[9,1],[4,10],[12,2],[6,1],[7,10]])
assert.equal(result, 17)
done()
})
it("People on the ship === 21", done => {
const result = algo.spaceNumbers([[3,0],[9,1],[4,8],[12,2],[6,1],[7,8]])
assert.equal(result, 21)
done()
})
it("People on the ship === 10", done => {
const result = algo.spaceNumbers([[21,10],[50,22],[4,12],[2,16],[6,12],[1,2]])
assert.equal(result, 10)
done()
})
})
// findTheLcd()
describe("Finding the common denominator", () => {
it(`Should return "(6,10)(10,10)"`, done => {
const result = algo.findTheLcd([ [3,5], [2,2] ] )
assert.equal(result, "(6,10)(10,10)")
done()
})
it(`Should return "(6,12)(9,12)(20,12)"`, done => {
const result = algo.findTheLcd([ [1,2], [3,4], [5,3] ] )
assert.equal(result, "(6,12)(9,12)(20,12)")
done()
})
it(`Should return "(45,60)(48,60)(40,60)"`, done => {
const result = algo.findTheLcd([ [3, 4], [4, 5], [2, 3] ] )
assert.equal(result, "(45,60)(48,60)(40,60)")
done()
})
it(`Should return "(10,26)(52,26)"`, done => {
const result = algo.findTheLcd([ [5,13], [4,2] ])
assert.equal(result, "(10,26)(52,26)")
done()
})
it(`Should return "(1,8)(4,8)(8,8)"`, done => {
const result = algo.findTheLcd([ [1,8], [1,2] ,[4,4] ])
assert.equal(result, "(1,8)(4,8)(8,8)")
done()
})
it(`Should return "(4,12)(15,12)(6,12)(9,12)"`, done => {
const result = algo.findTheLcd([ [2,6], [5,4], [1,2], [9,12] ])
assert.equal(result, "(4,12)(15,12)(6,12)(9,12)")
done()
})
it(`Should return "(4,12)(15,12)(6,12)(9,12)()"`, done => {
const result = algo.findTheLcd([ [2,6], [5,4], [1,2], [9,12] ])
assert.equal(result, "(4,12)(15,12)(6,12)(9,12)")
done()
})
})
})