Re: Array manipulation question
- From: Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@xxxxxxxxxxxxxxxx>
- Date: Fri, 30 May 2008 15:38:48 +0200
Henry schreef:
On May 30, 2:24 pm, Erwin Moller wrote:
<snip>
var firstVal = myArray[0];<snip>
for(var i=0;i<arrLength;i++){
if (myArray[i] != firstVal){
alert ("Black sheep found.");
break;
}}
You may as well start the loop counter at 1 as you already know that -
firstVal - will be equal to - myArray[i] - when - i - is zero as you
just set it to that value. (Or was that a deliberate mistake as a
learning exercise?)
Totally true Henry. A few wasted CPU cycles.
A better routine would also check for the number of array elements and stuff like that (eg refuse if only 1 element, or refuse if 0.).
I just wanted the guy to have some material to work with, and didn't give the code too much thought. ;-)
Regards,
Erwin Moller
.
- References:
- Array manipulation question
- From: DL
- Re: Array manipulation question
- From: Erwin Moller
- Re: Array manipulation question
- From: Henry
- Array manipulation question
- Prev by Date: Long term Consulting Assignment?
- Next by Date: Re: regex failing
- Previous by thread: Re: Array manipulation question
- Next by thread: Re: Array manipulation question
- Index(es):