Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18719 > unrolled thread

can I rewrite this replace to use only one loop

Started by"Tony" <tony.johansson@inport.com>
First post2013-03-05 12:37 +0100
Last post2013-03-05 14:31 +0100
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  can I rewrite this replace to use only one loop "Tony" <tony.johansson@inport.com> - 2013-03-05 12:37 +0100
    Re: can I rewrite this replace to use only one loop "Tony" <tony.johansson@inport.com> - 2013-03-05 12:46 +0100
    Re: can I rewrite this replace to use only one loop SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2013-03-05 14:31 +0100

#18719 — can I rewrite this replace to use only one loop

From"Tony" <tony.johansson@inport.com>
Date2013-03-05 12:37 +0100
Subjectcan I rewrite this replace to use only one loop
Message-ID<kh4lbt$3bg$1@dont-email.me>
In this for loop I loop through the array and replace - with /
var bytUt = /-/g;
            for (i = 0; i < tempArray.length; i++)
            {
                tempArray[i].ETATime = tempArray[i].ETATime.replace(bytUt, 
"/");
            }

In this for loop I loop through the array and replace T with " "
            var bytUt = /T/g;
            for (i = 0; i < tempArray.length; i++)
            {
                tempArray[i].ETATime = tempArray[i].ETATime.replace(bytUt, " 
");
            }

This works but can I replace this to a single for loop ?

//Tony 

[toc] | [next] | [standalone]


#18720

From"Tony" <tony.johansson@inport.com>
Date2013-03-05 12:46 +0100
Message-ID<kh4ls9$64b$1@dont-email.me>
In reply to#18719
I found it myself
var bytUt1 = /-/g;
            var bytUt2 = /T/g;
            for (i = 0; i < tempArray.length; i++)
            {
                tempArray[i].ETATime = tempArray[i].ETATime.replace(bytUt1, 
"/");
                tempArray[i].ETATime = tempArray[i].ETATime.replace(bytUt2, 
" ");
            }
//Tony

"Tony"  wrote in message news:kh4lbt$3bg$1@dont-email.me...

In this for loop I loop through the array and replace - with /
var bytUt = /-/g;
            for (i = 0; i < tempArray.length; i++)
            {
                tempArray[i].ETATime = tempArray[i].ETATime.replace(bytUt,
"/");
            }

In this for loop I loop through the array and replace T with " "
            var bytUt = /T/g;
            for (i = 0; i < tempArray.length; i++)
            {
                tempArray[i].ETATime = tempArray[i].ETATime.replace(bytUt, "
");
            }

This works but can I replace this to a single for loop ?

//Tony 

[toc] | [prev] | [next] | [standalone]


#18721

FromSAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid>
Date2013-03-05 14:31 +0100
Message-ID<5135f3b3$0$1402$ba4acef3@reader.news.orange.fr>
In reply to#18719
Le 05/03/13 12:37, Tony a écrit :
> In this for loop I loop through the array and replace - with /
> var bytUt = /-/g;
>             for (i = 0; i < tempArray.length; i++)
>             {
>                 tempArray[i].ETATime =
> tempArray[i].ETATime.replace(bytUt, "/");
>             }
>
> In this for loop I loop through the array and replace T with " "
>             var bytUt = /T/g;

for (var i = 0, n = tempArray.length; i<n; i++)
	{
	tempArray[i].ETATime = 
tempArray[i].ETATime.replace(/-/g,'/').replace(/T/g,' ');
	}


-- 
Stéphane Moriaux avec/with iMac-intel

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web