From: Mike Duffy on
"Mel Smith" <med_cutout_syntel(a)aol.com> wrote in news:84lb67F19cU1
@mid.individual.net:

>>>What's the difference between a Duck ?
>>
>> See: http://www.swiftys.org.uk/wiz?1461
>
> Sorry, the answer is:
>
> "One of its legs is both the same."
>
> (and note the correct usage of "its" )
>
> You guys 'quack me up' !
>
> but enough already :(

Yeh, flock off!
From: Garrett Smith on
David Mark wrote:
> Garrett Smith wrote:
>
[...]
>
> I just don't care to evaluate the length property each time through (or
> to splice one member at a time), even in an example. And though
> slightly longer, I consider mine to be easier to understand at a glance.

It is not surprising that you would find your solution easier to
understand; you wrote it. However, it is longer and more complicated.
Although the while loop was very fast, it was not as fast as the for loop.

Cyclomatic complexity is number of decisions +1.

The while-loop based function has a while loop, a nested while loop, and
two decisions: `if` and ternary `?`. It has a count of 5.

The for loop with one decision has a count of 3.

If I am wrong about the cyclomatic complexity calculation, somebody
please correct me.

Neither are very complicated, but the for loop is shorter, simpler, and
more straightforward. It wins by a small margin.

The array filter approach not as fast, as is to be expected, however it
is the simplest of all, with cyclomatic complexity of 2.

> YMMV.
>
> The strict comparison is a good idea in this case though.

Making sure the code does what expected of it is the most important thing.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: David Mark on
Garrett Smith wrote:
> David Mark wrote:
>> Garrett Smith wrote:
>>
> [...]
>>
>> I just don't care to evaluate the length property each time through (or
>> to splice one member at a time), even in an example. And though
>> slightly longer, I consider mine to be easier to understand at a glance.
>
> It is not surprising that you would find your solution easier to
> understand; you wrote it. However, it is longer and more complicated.
> Although the while loop was very fast, it was not as fast as the for loop.
>
> Cyclomatic complexity is number of decisions +1.
>
> The while-loop based function has a while loop, a nested while loop, and
> two decisions: `if` and ternary `?`. It has a count of 5.
>
> The for loop with one decision has a count of 3.
>
> If I am wrong about the cyclomatic complexity calculation, somebody
> please correct me.
>
> Neither are very complicated, but the for loop is shorter, simpler, and
> more straightforward. It wins by a small margin.
>
> The array filter approach not as fast, as is to be expected, however it
> is the simplest of all, with cyclomatic complexity of 2.

I think you are oversimplifying. For one, it depends very much on the
data in this case. Only way to be sure is to benchmark it with various
data sets. I can't say as I'm interested enough to do it though.
From: Garrett Smith on
David Mark wrote:
> Garrett Smith wrote:
>> David Mark wrote:
>>> Garrett Smith wrote:
>>>

[...]

>> The array filter approach not as fast, as is to be expected, however it
>> is the simplest of all, with cyclomatic complexity of 2.
>
> I think you are oversimplifying. For one, it depends very much on the
> data in this case. Only way to be sure is to benchmark it with various
> data sets. I can't say as I'm interested enough to do it though.
How does cyclomatic complexity depend on the data?

[1,2,3,4,5,2,4,21,7,4,2,8].filter(function(i){
return i !== 3;
});


I count one decision: i !== 3.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Ry Nohryb on
On May 9, 4:14 am, David Mark <dmark.cins...(a)gmail.com> wrote:
> Garrett Smith wrote:
>
> [...]
>
>
>
> > How about a forward loop using splice?
>
> > function removeThrees(a) {
> >   for(var i = 0; i < a.length; i++) {
> >     if(a[i] === 3) {
> >       a.splice(i,1);
> >     }
> >   }
> >   return a;
> > }
>
> I just don't care to evaluate the length property each time through (or
> to splice one member at a time), even in an example.  And though
> slightly longer, I consider mine to be easier to understand at a glance.
>  YMMV.
>
> The strict comparison is a good idea in this case though.

Hey, that code skips over any item coming after a 3... geniuses!
--
Jorge.