Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
d935a2a8
...
d935a2a8b7d32cf0681041a5deec472da766baaf
authored
2012-05-24 16:01:36 -0600
by
Harrison Reiser
Committed by
Nicolas Perriault
2012-05-27 10:03:02 +0200
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix math in the 10^9 range
1 parent
bb3dec01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
samples/googlematch.coffee
samples/googlematch.js
samples/googlematch.coffee
View file @
d935a2a
...
...
@@ -15,7 +15,7 @@ casper = require('casper').create verbose: true
casper
.
fetchScore
=
->
@
evaluate
->
result
=
document
.
querySelector
(
'#resultStats'
).
innerText
~~
(
/Environ ([0-9\s]{1,}).*/
.
exec
(
result
)[
1
].
replace
(
/\s/g
,
''
)
)
parseInt
/Environ ([0-9\s]{1,}).*/
.
exec
(
result
)[
1
].
replace
(
/\s/g
,
''
)
terms
=
casper
.
cli
.
args
# terms are passed through command-line arguments
...
...
@@ -38,7 +38,7 @@ casper.each terms, (self, term) ->
self
.
echo
"
#{
term
}
:
#{
score
}
"
casper
.
run
->
scores
.
sort
->
(
a
,
b
)
->
b
.
score
-
a
.
score
;
winner
=
scores
[
0
]
winner
=
x
for
x
in
scores
when
x
.
score
>
winner
.
score
@
echo
"Winner is
#{
winner
.
term
}
with
#{
winner
.
score
}
results"
@
exit
()
...
...
samples/googlematch.js
View file @
d935a2a
...
...
@@ -16,7 +16,7 @@ var casper = new require('casper').create({
casper
.
fetchScore
=
function
()
{
return
this
.
evaluate
(
function
()
{
var
result
=
document
.
querySelector
(
'#resultStats'
).
innerText
;
return
~~
(
/Environ
([
0-9
\s]{1,})
.*/
.
exec
(
result
)[
1
].
replace
(
/
\s
/g
,
''
));
return
parseInt
(
/Environ
([
0-9
\s]{1,})
.*/
.
exec
(
result
)[
1
].
replace
(
/
\s
/g
,
''
));
});
};
...
...
@@ -45,10 +45,10 @@ casper.each(terms, function(self, term, i) {
});
casper
.
run
(
function
(
self
)
{
scores
.
sort
(
function
(
a
,
b
)
{
return
b
.
score
-
a
.
score
;
});
var
winner
=
scores
[
0
];
for
(
var
i
=
0
,
len
=
scores
.
length
;
i
<
len
;
i
++
)
if
(
scores
[
i
].
score
>
winner
.
score
)
winner
=
scores
[
i
];
self
.
echo
(
'winner is "'
+
winner
.
term
+
'" with '
+
winner
.
score
+
' results'
);
self
.
exit
();
});
...
...
Please
register
or
sign in
to post a comment