-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.html
More file actions
140 lines (131 loc) · 4.04 KB
/
index.html
File metadata and controls
140 lines (131 loc) · 4.04 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
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
<!DOCTYPE html>
<html>
<head>
<title>Function Practice</title>
<link rel="stylesheet" href="./app.css" />
</head>
<body>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="./app.js"></script>
<script>
$(document).ready(function() {
function wordCount(fragment) {
if(!fragment) {
return 0;
}
return fragment.trim().split(/\s+/).length;
}
createExample('Word Count', {
description: 'Create a function that returns the number of words in \
a fragment of text',
implementation: wordCount,
validation: [
{
input: 'one two three',
output: 3
},
{
input: ' ignore spaces ',
output: 2
},
{
input: null,
output: 0
}
]
});
/**
* Reverses the text in the input string
*/
function reverseText(text) {
if(text === null) {
return null;
}
var reversed = '';
for(var index = text.length - 1; index >= 0; index--) {
reversed += text[index];
}
return reversed;
}
createExample('Reverse Text', {
description: 'Create a function that reverses the characters in \
a string',
implementation: reverseText,
validation: [
{
input: 'test value',
output: 'eulav tset'
},
{
input: null,
output: null
},
{
input: '',
output: ''
}
]
});
createExample('Tender Change', {
description: 'Write a function that given a dollar amount returns \
the change in bills and coins. For instance, given \
<code>7.23</code> it should return: \
<pre>{ fives: 1, ones: 2, dimes: 2, pennies: 3 }</pre>',
implementation: null,
validation: [
{
input: 7.23,
output: { fives: 1, ones: 2, dimes: 2, pennies: 3 }
}
]
});
createExample('The Pluralizer', {
description: 'Write a function that takes two arguments, a noun \
and a number, and returns the number and the noun in pluralized \
form (for instance, "1 dog", "5 cats")',
implementation: null,
validation: [
{
input: ['dog', 1],
output: '1 dog'
},
{
input: ['cat', 5],
output: '5 cats'
}
]
});
var movieList = [
'The Shawshank Redemption,1994,1043071',
'The Godfather,1972,732416',
'The Godfather: Part II,1974,474640',
'Pulp Fiction,1994,806431',
'The Dark Knight,2008,1017508',
'12 Angry Men,1957,255846',
'Schindler\'s List,1993,528900',
'The Lord of the Rings: The Return of the King,2003,738931',
'Fight Club,1999,791186',
'Star Wars: Episode V - The Empire Strikes Back,1980,503348'
];
createExample('Movie Parsing', {
description: "Given the following comma separated list of IMDb top \
rated movies: <pre>var movieList = " +
JSON.stringify(movieList, null, ' ') +
"</pre> create a function that splits the values into the title, \
year, and number of votes and returns a list of movie objects \
sorted by year.",
implementation: null,
validation: [
{
input: [ movieList ],
output: [
// enter sorted, formatted list here...
]
}
]
});
});
</script>
</body>
</html>