Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cd711ae

Browse files
Create regexp_golf_completejavascript.com.js
1 parent d3df683 commit cd711ae

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Fill in the regular expressions
2+
3+
verify(/ca(r|t)/,
4+
["my car", "bad cats"],
5+
["camper", "high art"]);
6+
7+
verify(/pr?op/,
8+
["pop culture", "mad props"],
9+
["plop"]);
10+
11+
verify(/ferr(e|y|a)(\w*)/,
12+
["ferret", "ferry", "ferrari"],
13+
["ferrum", "transfer A"]);
14+
15+
verify(/(\w+)?ious\b/,
16+
["how delicious", "spacious room"],
17+
["ruinous", "consciousness"]);
18+
19+
verify(/\s[.,:;]/,
20+
["bad punctuation ."],
21+
["escape the dot"]);
22+
23+
verify(/(\w){7,}/,
24+
["hottentottententen"],
25+
["no", "hotten totten tenten"]);
26+
27+
verify(/^(\w+[^e]+|[^e]+\w+)$/,
28+
["red platypus", "wobbling nest"],
29+
["earth bed", "learning ape"]);
30+
31+
32+
function verify(regexp, yes, no) {
33+
// Ignore unfinished exercises
34+
if (regexp.source == "...") return;
35+
yes.forEach(function(s) {
36+
if (!regexp.test(s))
37+
console.log("Failure to match '" + s + "'");
38+
});
39+
no.forEach(function(s) {
40+
if (regexp.test(s))
41+
console.log("Unexpected match for '" + s + "'");
42+
});
43+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /