PDA

View Full Version : I don't know if this is possible or not...



SessTehKing
04-04-2007, 12:42 AM
But, could a script output an array of text in order? i.e. a, b, c, d, e, f, g, etc., etc.

But to a large proportion? Like aaaaaaaa all the way to zzzzzzzz?

If it is possible, would the script have to include everything in between the sequences?

Thanks in advance.

eXceed69
04-04-2007, 02:20 AM
Yes it is possible, maybe your talking about sorting?right?

SessTehKing
04-04-2007, 01:48 PM
No...outputing an array of text. All the way from aaaaaaaa to zzzzzzzz.

i.e. aaaaaaaa, aaaaaaab, aaaaaaac, - aahilsne, aahilsnf - zzzzzzzy, zzzzzzzz

A lot of text, yea, but it'd be very helpful. Is that possible?

pcbrainbuster
04-04-2007, 04:26 PM
Well I have low experience at arrays seeing as I don't completely understand them yet but as far as I know about it you can eigther write it yourself in order or use something like sort (but i'm very unsure)....

Well I guess will spend my time right now looking it up for you :)...

I will post back when I have some results....

pcbrainbuster
04-04-2007, 04:27 PM
LOL, I already found the answer -
http://www.mickweb.com/javascript/arrays/sortingArrays.html

jscheuer1
04-04-2007, 04:39 PM
How do:

aahilsne, aahilsnf

fit in this sequence:

aaaaaaaa, aaaaaaab, aaaaaaac, . . . , zzzzzzzy, zzzzzzzz

? In fact, how do you get from incrementing the last letter each time as in the first three entries to having all but the last letter incremented? Anyways, there might be a way to fit all that into a logical progression. For the time being there is this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var theStrings=[];
var aString=[97,97,97,97,97,97,97,97];
var pos=aString.length-1
function buildArray(){
var str='';
for (var i_tem = 0; i_tem < aString.length; i_tem++)
str+=String.fromCharCode(aString[i_tem]);
theStrings[theStrings.length]=str;
}
function incString(){
pos=pos<0? aString.length-1 : pos;
aString[pos--]++;
}
while (aString[0]<122){
buildArray();
incString();
}
theStrings[theStrings.length]='zzzzzzzz';
</script>
</head>
<body>
<script type="text/javascript">
for (var i_tem = 0; i_tem < theStrings.length; i_tem++)
document.write(theStrings[i_tem]+'<br>\n');
</script>
</body>
</html>

SessTehKing
04-04-2007, 11:15 PM
i.e. aaaaaaaa, aaaaaaab, aaaaaaac, - aahilsne, aahilsnf - zzzzzzzy, zzzzzzzz

The dashes signified "through"

That is close to what I need, thank you, but I need it with much more info...

I need it to go from aaaaaaaz to aaaaaaba, then continue from that to aaaaaabz, then go to aaaaaaca, etc., etc.

It'll be MUCH longer then that, but would be really helpful if that would be possible.

Twey
04-04-2007, 11:33 PM
I know what you mean, but it sounds like a homework assignment to me...

mburt
04-05-2007, 12:50 AM
Sometimes (always, actually) getting the answer via search engine will help. Pointlessly posting questions on forums gets annoying from time to time.
http://www.google.ca/search?hl=en&client=firefox-a&rls=org.mozilla&#37;3Aen-US%3Aofficial&hs=8aa&q=javascript+sort+letter&btnG=Search&meta=

mburt
04-05-2007, 01:30 AM
This is also a possibility:

<script type="text/javascript">
var test=["mike","jaen","lard","wavey","karyn","azulin"];
Array.prototype.arr_sort = function(it) {
var n = this,x=Array();
n.sort();
for (var i=0;i<n.length;i++) {
x.push(n[i]);
}
if (typeof it == "undefined") {
return x;
}
else {
return n[it];
}
}

var myArray = test.arr_sort();
alert(myArray[3])
</script>

jscheuer1
04-05-2007, 04:24 AM
I know what you mean, but it sounds like a homework assignment to me...

How perceptive, Twey.

OK, so maybe not but, if not, what the heck is this for?

My money, for now, is on Twey.

jscheuer1
04-05-2007, 07:08 AM
Still, it intrigues me. Basically, you just want to count to whatever in base 26.

Twey
04-05-2007, 11:22 AM
Not quite, since he wanted to go from aaaaaa to zzzzzz, not from a to zzzzzz. It's not so challenging that way:
function incDigit(s, p) {
var p = p || 0;
if(p >= s.length)
return false;
if(typeof s === "string")
s = s.split("");
s[p] = String.fromCharCode(s[p].charCodeAt(0) + 1);
if(s[p] === "{") {
s[p] = "a";
return incDigit(s, p + 1);
} else
return s.join("");
}

for(var c = "aaaaaa"; c = incDigit(c);)
document.write(c.split("").reverse().join("") + " ");Warning: there are lots of them.

jscheuer1
04-05-2007, 12:33 PM
Not quite, since he wanted to go from aaaaaa to zzzzzz, not from a to zzzzzz. It's not so challenging that way:
function incDigit(s, p) {
var p = p || 0;
if(p >= s.length)
return false;
if(typeof s === "string")
s = s.split("");
s[p] = String.fromCharCode(s[p].charCodeAt(0) + 1);
if(s[p] === "{") {
s[p] = "a";
return incDigit(s, p + 1);
} else
return s.join("");
}

for(var c = "aaaaaa"; c = incDigit(c);)
document.write(c.split("").reverse().join("") + " ");Warning: there are lots of them.

More than you think:


aaaaaaaa all the way to zzzzzzzz


Well, at least the fellow's done his homework.

Twey
04-05-2007, 02:53 PM
Yeah, his teacher just has to leave it running for a night or so to get the output... :p

SessTehKing
04-05-2007, 04:54 PM
No, it's not homework. And that code was what I was looking for, just had to add 2 a's, and yes, it does take a while, and FireFox keeps asking if I want to cancel or continue the script every 5 seconds...

But yea...I'm trying to collaborate this with PHP. Could I make it output some PHP script and a line of that array, for example just aaaaaaaa, within the script somewhere, then continue?

Twey
04-05-2007, 05:01 PM
OK, I didn't understand what you meant by that. Can you clarify?

SessTehKing
04-05-2007, 08:10 PM
Could I make that script output the text inside of stuff? Like PHP tags...

i.e.

if(file_exists("aaaaaaaa.htm"))
$fp = fopen("aaaaaaaa.htm", "a+")
fwrite($fp, "some HTML")
fclose($fp)
if(file_exists("aaaaaaaab.htm"))
$fp = fopen("aaaaaaab.htm", "a+")
fwrite($fp, "some HTML")
fclose($fp)

And continue going? Like, that script outputs the array of letter, can it output normal text also everytime it does a different letter?

jscheuer1
04-05-2007, 08:13 PM
You probably could but, I will let Twey who knows PHP much better than I do answer that part. I just wanted to add in here that - If you were going to need this spectrum of base 26 numbers generated on a regular basis, you would be much better off just running it once and then cutting and pasting the output to a hard coded array.

Twey
04-05-2007, 08:27 PM
Not from Javascript you can't, no. Furthermore, John's right: the resources required to generate this list are prohibitive. You'd be better off storing it in memory, or on disk and reading it a line at a time.

SessTehKing
04-06-2007, 12:55 AM
I was afraid of that... :/

Thanks very much, though.

jscheuer1
04-07-2007, 06:05 AM
I think you are both giving up too easily. Once you've generated the values, they could be stored in a database, text file, or in a PHP array. Wherever you put them, they could then be retrieved from there for use in your PHP code. Each entry could also have other values associated with it and these could be pulled and used if some condition matches the main entry value.