Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Community Boards > Just for Kicks Challenges

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-04-2005, 08:32 PM   #1
madgett
is my last name...
 
Join Date: May 2004
Posts: 964
Default Challenge - Extending the String Class

Ok, for those of you who complained about the hundredth time someone challenged for the rotating cube...

Try this:
Extend the String Class so that...

A) The class has all of the methods of the String Class
B) Adds only 1 other method which allows for the String to be split by muliple delimiters. Must return an array. (Much like the original split() but better )
C) Class must be 25 lines of code or less. Only {} Don't count.
D) Must be your own work...obviously.

E)...It must have a constructor. -added within 5mins of thread post-

The class with the most capability and fewest lines wins. Abviously following the list above.

I will post mine after we get a few going...I've already done it.

Last edited by madgett; 04-04-2005 at 08:37 PM.. Reason: Constructor must be in the class
madgett is offline   Reply With Quote
Old 04-04-2005, 09:06 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

what do you mean by "better"?
__________________
(6)
senocular is offline   Reply With Quote
Old 04-04-2005, 09:10 PM   #3
madgett
is my last name...
 
Join Date: May 2004
Posts: 964
Default

The split() command current only accepts 1 delimiter set. "," or ",#" etc...but that's only 1, I am saying come up with a Class that extends String that allows for multiple delimiter sets at the same time instead of one. Know what I mean? So you would be able to use "," and ",#" if you so choose.
madgett is offline   Reply With Quote
Old 04-04-2005, 09:57 PM   #4
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

you mean something like this?
ActionScript Code:
Array.prototype.toString = function(){     return "[" + this.join(",") + "]"; } String.prototype.split2 = function(d,a){     if ((d=arguments.shift()) != undefined && (a=this.split(d))) for(var i in a) a[i]=this.split2.apply(a[i],arguments);     return d != undefined ? a : this; } var str = "oneA,twoA|oneB|oneC,twoC,threeC|oneD,twoD"; trace(str.split2("|",",")); // [[oneA,twoA],[oneB],[oneC,twoC,threeC],[oneD,twoD]]
__________________
(6)
senocular is offline   Reply With Quote
Old 04-04-2005, 10:10 PM   #5
madgett
is my last name...
 
Join Date: May 2004
Posts: 964
Default

Looks very interesting senocular, now all you have to do is make it a ActionScript Class that extends the String Class and returns an array. Make sure you have A-E.
madgett is offline   Reply With Quote
Old 04-04-2005, 10:44 PM   #6
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

eh, its just a syntax thing
__________________
(6)
senocular is offline   Reply With Quote
Old 04-04-2005, 10:49 PM   #7
madgett
is my last name...
 
Join Date: May 2004
Posts: 964
Default

If you do:
ActionScript Code:
var my_str:String = "P,A,T,S,Y"; var my_array:Array = my_str.split(","); for (var i = 0; i<my_array.length; i++) {   trace(my_array[i]); }
You get:
Code:
output:
  P
  A
  T
  S
  Y
I'm getting nested arrays with your prototypes. Use a class . Ideally you should get the same output even using the multiple delimiter technique which the challenge is proposing.
madgett is offline   Reply With Quote
Old 04-04-2005, 11:35 PM   #8
Xeef
Off-Line
 
Xeef's Avatar
 
Join Date: Aug 2004
Location: Ibiza/Spain language :Hungarian/German/ abit English
Posts: 6,539
Default

here one line
hope you not think i will make a class for ONE line ?
PHP Code:
String.prototype.split2 = function() {
    return 
arguments[0] ? this.split2.apply(this.split(arguments.shift()).join("º"), arguments) : this.split("º");
};
"Hallo-by?Xeef:just:for?testing-blabla;more$testing)to>By/sure";
trace(a.split2("-""?"":"">""/""$"")"";""this to test if not in""F")); 
one bad thing "º" sucks
Xeef is offline   Reply With Quote
Old 04-05-2005, 12:51 AM   #9
madgett
is my last name...
 
Join Date: May 2004
Posts: 964
Default

Well, anyone can prototype in few lines...but that's not the challenge, I want to see some classes. To get the fewest lines in a class is more challenging. You guys came up with some great stuff, but use a class. In the String.split() function there's a "limit" parameter, those prototypes don't include that.

Also, Xeef your prototype fails if you use º in the string. I'm sure a class couldn't be that much more difficult...I mean c'mon. My entire class with the contructor is 17 lines. Shoot for that.
madgett is offline   Reply With Quote
Old 04-05-2005, 01:11 AM   #10
Xeef
Off-Line
 
Xeef's Avatar
 
Join Date: Aug 2004
Location: Ibiza/Spain language :Hungarian/German/ abit English
Posts: 6,539
Default

to do a class is no problem but for what ?
it's like make a chalenge to write a class which trace a variable to screen
in such a case i write
trace(var)
and not make a class
it's a bit like taking cement stones and a roof for go camping
where by what woud by the advantage of a class in oposite to the prototypes you see above ?

Quote:
Also, Xeef your prototype fails if you use º in the string
as you can see the last line of my message i am aware of this my objective was to make it as short as possible
Xeef is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:47 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.