This repository was archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathcoffeescript.yml
More file actions
91 lines (70 loc) · 2.95 KB
/
Copy pathcoffeescript.yml
File metadata and controls
91 lines (70 loc) · 2.95 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
cw-2:
algorithms:
initial: |-
# return the two oldest/oldest ages within the array of ages passed in.
# it should return the two ages as a sorted array, youngest age first
twoOldestAges = (ages) ->
answer: |-
twoOldestAges = (ages) ->
oldest = 0
nextOldest = 0;
for age in ages
if age > oldest
nextOldest = oldest
oldest = age
else if age > nextOldest
nextOldest = age
[nextOldest, oldest]
fixture: |-
Test.describe "twoOldestAges([1,5,87,45,8,8])", ->
results1 = twoOldestAges [1,5,87,45,8,8]
Test.it "Should return something that isn't falsy", ->
Test.expect results1, "Something is wrong, twoOldestAges([1,5,87,45,8,8]) has no results!"
Test.it "Should return [45,87]", ->
Test.assertEquals results1[0], 45, "twoOldestAges([1,5,87,45,8,8]) should return 45 as the second highest result"
Test.assertEquals results1[1], 87, "twoOldestAges([1,5,87,45,8,8]) should return 87 as the second highest result"
Test.describe "twoOldestAges([6,5,83,5,3,18])", ->
results2 = twoOldestAges [6,5,83,5,3,18]
Test.assertSimilar results2, [18, 83]
bug fixes:
initial: |-
class Person
constructor: (@name) ->
#TODO: The greet function is not returning the expected value.
greet: -> "Hello my name is #{name}"
answer: |-
class Person
constructor: (@name) ->
greet: -> "Hello my name is #{@name}"
fixture: |-
jack = new Person "Jack"
jill = new Person "Jill"
Test.expect jack.name == "Jack", "person.name property does have have a valid value"
Test.expect jack.greet() == "Hello my name is Jack"
Test.expect jill.greet() == "Hello my name is Jill"
refactoring:
initial: |-
# TODO: This method needs to be called multiple times for the same person (myName).
# It would be nice if we didnt have to always pass in myName every time we needed to great someone.
greet = (myName, yourName) -> "Hello #{yourName}, my name is #{myName}"
answer: |-
class Person
constructor: (@name) ->
greet: (yourName) ->
"Hello #{yourName}, my name is #{@name}"
fixture: |-
jack = new Person "Jack"
jill = new Person "Jill"
Test.expect jack.greet("Jill") == "Hello Jill, my name is Jack"
Test.expect jack.greet("Mary") == "Hello Mary, my name is Jack"
Test.expect jill.greet("Jack") == "Hello Jack, my name is Jill"
reference:
initial: |-
websites = []
answer: |-
# add the values "codewars" to the websites array
websites = ["codewars"]
fixture: |-
Test.expect(websites.length > 0, 'The array is still empty')
Test.expect(websites.length == 1, 'The array contains too many values')
Test.expect(websites[0] == 'codewars', 'The array does not contain the correct value "codewars"')