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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In Pascal, there are sets. I was just wondering if there is any way

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
In Pascal, there are sets.<br><br>I was just wondering if there is any way you can use sets in javascript?<br><br>for example (this is a statement in pascal)<br><br>for i:=1 to 5 do<br>if i in [3..5] then<br>writeln(i);<br><br>thanks for any help<br> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
are sets in any ways similar to arrays, in otherwords, having say int[5] being 5 entries for that type, and can refer to it by its index, or like char[4,5] <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
no, not really.<br><br>a set is a non-ordinal, standard data type. A set cannot contain two of the same values.<br><br>here is an example (I have converted to javascript as much as possable, so don't put this into a pascal compiler, or a javascriptlet :) ):<br><br>var myset=set of char<br>vari=0;<br>myset=[1,2,4,8] <br>//a set with the numbers 1,2,4&8<br>myset+=[5]<br>//add the number 5 to the set<br>for (i=0;i&lt;15;i++){<br>if (i in myset){alert(i)}<br>}<br><br>//this loops through 15 slots, and if they are 1,2,4,5,or 8<br>//alert the number<br><br>That should explain most of what sets can do. <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
hehe, I myself am not big into javascript, I understand C++ and VB more, but I can figure it out. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
Javascript allows you to create new objects, so there's no reason you couldn't simulate the set functionality as a new object.&nbsp;&nbsp;Of course, the syntax would be different than in Pascal, but the functionality could be the same (or close)<br><br> <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
I seem to have found something, but might need help in decoding it.&nbsp;&nbsp;I found it in the javascript forum, in a thread called: &quot;Validating forms with an exception&quot;<br><br>in the response, it includes things like &quot;<i>new regExp(....)</i>&quot;, and in the quotes is a range of stuff. Can any of you peoples help me figure this out? <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Hold on a minute. I just thought of something, and now I feel kind of stupid for not thinking of it.<br><br>here:<br><br>function funcName(stringToCheck){<br>var myset=&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot;<br>if (myset.indexOf(stringToCheck.substring(0,1))!=-1){<br>//do junk!!!}}<br><br>anyway, if you didn't understand my clump of garbeled code, I just used the indexOf operator to determine if the first letter of a string is in a given set!!!<br><br>Thanks for your help, anyways <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top