forked from liammclennan/JavaScript-Koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_regular_expressions.js
More file actions
35 lines (26 loc) · 1.04 KB
/
about_regular_expressions.js
File metadata and controls
35 lines (26 loc) · 1.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
$(document).ready(function(){
module("About Regular Expressions (topics/about_regular_expressions.js)");
test("exec", function() {
var numberFinder = /(\d).*(\d)/;
var results = numberFinder.exec("what if 6 turned out to be 9?");
ok(results.equalTo([__, __, __]), 'what is the value of results?');
});
test("test", function() {
var containsSelect = /select/.test(" select * from users ");
equals(containsSelect, __, 'does the string provided contain "select"?');
});
test("match", function() {
var matches = "what if 6 turned out to be 9?".match(/(\d)/g);
ok(matches.equalTo([__, __]), 'what is the value of matches?');
});
test("replace", function() {
var pie = "apple pie".replace("apple", "strawberry");
equals(pie, __, 'what is the value of pie?');
pie = "what if 6 turned out to be 9?".replace(/\d/g, function(number) { // the second parameter can be a string or a function
var map = {'6': 'six','9': 'nine'};
return map[number];
});
equals(pie, __, 'what is the value of pie?');
});
// THE END
});