From: Ry Nohryb on
On May 14, 6:17 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
> MikeMainFrame wrote:
>
> > I have followed your discussions and want to suggest this:
> > function removeThrees(a) {
> > var jx=0;
> > for (var ix = 0; ix < a.length; ix++) {
> > if(a[ix] !== 3) {
> > a[jx] = a[ix]
> > jx++;
> > }
> > }
> > return a.splice(0,jx);
> > }
>
> That's clearer and more efficient.

No, genius, no.

> > Bubbles up the ones you need to delete - then cut off on the way
> > back ...
> Shifts the set of good elements to the front and saves the length of
> that set each iteration.

No, it does not shift them it *duplicates* them, and in the process,
it makes sparse arrays dense :

a= [];
a[10]= 27;
for (p in a) console.log(p);
--> 10
5 in a
--> false

for (p in removeThrees(a)) console.log(p);
--> 0,1,2,3,4,5,6,7,8,9,10
5 in a
--> true

> (...)
--
Jorge.
From: David Mark on
Garrett Smith wrote:

>
> Seems to be the opposite where I live. Endorsing a library has become
> nearly a requirement for any professional jobs here. Not a jQuery fan?
> Good luck.

So endorse your own and/or demonstrate why the shop is making a mistake
hiring "fans" of jQuery. Look at the results.
From: Dr J R Stockton on
In comp.lang.javascript message <16586391-3d42-49f6-89a6-a2015b993d1a(a)k1
9g2000yqm.googlegroups.com>, Fri, 7 May 2010 05:27:23, Dmitry A.
Soshnikov <dmitry.soshnikov(a)gmail.com> posted:

>
>"Let there is an array. How to remove all elements with value 3 from
>it?"
>

The first response should be to ask whether 3 is a Number value or a
String value.

Another is to ask whether the gaps must be closed up : if the array is
long, it could be better to replace the threes with null or undefined,
if the application using the array will not mind.

One should check whether order must be preserved - it is conceivable
that it might be best to use the default sort method, which should be
quick, then to remove the now-contiguous threes in one go. After all,
the intent may have been to sort the array next. And if the entries
look otherwise like current dates as seconds-from-epoch, then sorting
brings the threes to the front.


However, there can be no point in removing the threes unless the whole
of the purified array will be used later; and the speed of the
purification is unimportant as long as it does not significantly delay
the final result. Therefore, the simplest and most readily maintainable
method is probably best : scan the whole of the array, and push any
element which is not three into another array to be used for the rest of
the job (assumption : that there is enough memory for both arrays).

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)