-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel4.js
86 lines (78 loc) · 2.48 KB
/
level4.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
import test from 'tape'
import getCards from './lib/get-cards'
import { map, filter, reduce, compose } from 'nanofp'
export default function() {
const ex1 = 'Use map to transform list of card data to list of images'
const exercise1 = _ => {
const data = getCards()
return null
}
const ex2 = 'Use filter to filter list of cards of the suit clubs'
const exercise2 = _ => {
const data = getCards()
return null
}
const ex3 =
'Use reduce and count the number of cards that have a value of 8 or value of 6'
const exercise3 = _ => {
const data = getCards()
return null
}
const ex4 = `Use map, filter and reduce with compose
to show all cards as images that contain values of 8 or 6`
const exercise4 = _ => {
const data = getCards()
return null
}
/* tests to validate exercises go here */
test('test', assert => {
assert.plan(4)
assert.same(
exercise1(),
[
'<img src=http://deckofcardsapi.com/static/img/6H.png />',
'<img src=http://deckofcardsapi.com/static/img/7H.png />',
'<img src=http://deckofcardsapi.com/static/img/KS.png />',
'<img src=http://deckofcardsapi.com/static/img/2D.png />',
'<img src=http://deckofcardsapi.com/static/img/QS.png />',
'<img src=http://deckofcardsapi.com/static/img/0C.png />',
'<img src=http://deckofcardsapi.com/static/img/8H.png />',
'<img src=http://deckofcardsapi.com/static/img/JD.png />',
'<img src=http://deckofcardsapi.com/static/img/8C.png />'
],
ex1
)
assert.same(
exercise2(),
[
{
code: '0C',
image: 'http://deckofcardsapi.com/static/img/0C.png',
images: {
png: 'http://deckofcardsapi.com/static/img/0C.png',
svg: 'http://deckofcardsapi.com/static/img/0C.svg'
},
suit: 'CLUBS',
value: '10'
},
{
code: '8C',
image: 'http://deckofcardsapi.com/static/img/8C.png',
images: {
png: 'http://deckofcardsapi.com/static/img/8C.png',
svg: 'http://deckofcardsapi.com/static/img/8C.svg'
},
suit: 'CLUBS',
value: '8'
}
],
ex2
)
assert.equals(exercise3(), 3, ex3)
assert.equals(
exercise4(),
'<img src=http://deckofcardsapi.com/static/img/6H.png /><img src=http://deckofcardsapi.com/static/img/8H.png /><img src=http://deckofcardsapi.com/static/img/8C.png />',
ex4
)
})
}