-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathchallenge.js
66 lines (54 loc) · 1.51 KB
/
challenge.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
function Challenge (rawData) {
var data = JSON.parse(rawData)
this._data = data
this.name = data.name
this.description = data.description
this.slug = data.slug
if (data.session) {
this.setup = data.session.setup
this.tests = data.session.exampleFixture
this.solutionId = data.session.solutionId
this.projectId = data.session.projectId
}
if (typeof data.rank === 'object') {
this.rank = data.rank.id.toString().replace('-', '')
} else {
this.rank = data.rank.toString().replace('-', '')
}
this.language = data.language
}
Challenge.prototype.extensions = {
ruby: 'rb',
javascript: 'js'
}
Challenge.prototype.toString = function () {
var buff = '#' + this.name + '\n' +
'#' + this.rank + ' KYU' + '\n' +
'\n------' + '\n' +
'# Description' + '\n' +
this.description + '\n'
if (this.setup) {
buff = buff +
'\n------' + '\n' +
'# Provided code' + '\n```\n' +
this.setup + '\n```\n'
}
if (this.tests) {
buff = buff +
'# Provided tests' + '\n```\n' +
this.tests + '\n```\n'
}
return buff
}
Challenge.prototype.acceptedMessage = function () {
return '# Challenge started\n\n' +
this.instructions()
}
Challenge.prototype.instructions = function () {
var extension = this.extensions[this.language]
return 'To print these instructions again, run: `codewars print`\n' +
'To verify your solution, run: `codewars verify solution.' + extension + '`\n'
}
module.exports = function (args) {
return new Challenge(args)
}