Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing elements from diffrent arrays. 2

Status
Not open for further replies.

dragonkeeper

Technical User
Sep 2, 2002
9
US
the following code is not working. it appears the statement that evaluates array elements is not working as i intended.
But if i hard code a value in place of one the elements the code works as intended.What am i missing? code is pasted below.

Array.prototype.unique = function()
{
var i;
var j;
var b=new Array();

main:for(i=0;i<this.length;i++)
{
for (j=0;j<b.length;j++)
{
if(this==b[j])
{
continue main;
}

}

b[b.length]=this;


}
return b;
}
 
Thanks to everyone for their help, I knew that it was something very simple as well as stupid on my part. Thanks for putting me in the right direction.
 
[&nbsp;]
Thanks for the star even though you did not need my "solution".

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
I don't like the look of the regex using greedy match and then everybody, including your users, has to make assumption on the line breaks. If I give you all the benefit of the doubt, check this.
[tt]
alert(titleLang.length);
alert(titleLang.join("\n");
[/tt]
If worse comes to worse, alert the escape.
[tt]
for (var i=0; i<titleLang.length; i++) {
alert(escape(titleLang);
}
[/tt]
ps: What kind of conventions you adapt in scripting. Why are all the spaces between the object and the dot method? And var titleLang=new Array; constructor? I cannot say they will make thing wrong because javascript is very pardonning, but all the same, not impressive way to script. And then, what is the double </span>?!
 
tsuji

I don't like the look of the regex using greedy match
In the complete code the RegExp is non-greedy as it spans multiple lines.
Code:
title=" language:(.|\s)*?<\/la

Alerting the length or escaping the string is a good ideal.
It didn't occur to me to do this as normally I would have used Perl for this and used it's chomp function right off the bat. By doing so I never have this type of issues arise.

Why are all the spaces between the object and the dot method?
Typo I should have copy/paste.

Code:
var titleLang=new Array; another typo

 should have been "var titleLang=new Array();" or better yet "var titleLang=[];"


And then, what is the double </span>?!
As i stated before I didn't write the code that is being parsed. There are actually 5 spans for each block of code everything is written in to a span, then another span is used as a container. Hence the earlier statement about monkeys in the lab. It looks like the code was probably dynamically created.

ps: What kind of conventions you adapt in scripting.
Pretty much anything, I will normally use whatever is the best fit is for the job at hand. But for this I'm stuck using JavaScript. I'm building an HTA, and everything is being done client side.
My main two criteria are:
1. The code has to work on any machine here, that means developer station and non-developer station.

2.Ease of use.(manager has to be able to use it.)

Non-developer workstations do not have Perl installed and may or may not have any other run-times available.
The only thing i know for certain that is level across all workstations is IE.
I'm using an HTA to get around all the browser security issues as well as provide the standard look and feel of a GUI.

The team is mostly comprised of Java programmers thus they are more familiar with JavaScript than VbScript. So for maintainability it makes more since to use JavaScript. I guess it's not all bad, as I use activeX controls and WSH in my JavaScript.
Again, thanks for your help, it's much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top