/    Sign up×
Community /Pin to ProfileBookmark

Help with these functions

These are the task that I need to do and what i have done so far with no success, please help if you can ?

this is the task – returns an array of urls from pages for which the corresponding content matches pattern (in the style of function 3)

what I’ve done but doesn’t work – function urls(pages,pattern)
{
var pages=pattern.toUpperCase();
var pattern=pattern.toUpperCase();
for(var k=0;k<pattern.length;k++)
{
if(string.indexOf(pattern[k])<0)
return false;
}
return true;
}

the task – returns an array of records of the form {url: … , score: … } derived from web. Each record contains a url and the pattern score of its corresponding content.
Records with a score of zero are omit

what I’ve done but doesn’t work – function urlScores(web,pattern){
var result=[];
var record={};
for(i=0;i<web.length;i++){
var index=-1;
result[i]=0;
do{
index=web[i].url.toLowerCase().indexOf(pattern.toLowerCase()); index+1;
if(index>=0){
result[i]=result[i]+1;
record.url=web[i].url;
record.content=result[i];
}
}while (index>=0)
}
return record.url+””+record.content;
}

please help if you can, many thanks ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdNov 10.2015 — Haha

<i>
</i>index=web[i].url.toLowerCase().indexOf(pattern.toLowerCase()); index+1;


index is being reassigned silly. Should be something like:

<i>
</i>found=web[i].url.toLowerCase().indexOf(pattern.toLowerCase()); index+1;
Copy linkTweet thisAlerts:
@JMRKERNov 13.2015 — Invalid code
[code=php]
index+1;
[/code]
×

Success!

Help @tomdavid22 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...