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


Groups > comp.lang.javascript > #27625

Re: Swap arrays ones again.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: Swap arrays ones again.
Date Thu, 14 May 2015 16:12:29 +0100
Organization A noiseless patient Spider
Lines 39
Message-ID <87zj572nxe.fsf@bsb.me.uk> (permalink)
References <974af16e-3a67-4d6c-944a-af27660f05a8@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="19540"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rMcBIAHzmxZ67AK/vGj0z/wJnCrTIHhM="
Cancel-Lock sha1:d4aSkgtFlglyRq3gV0Z78Bo28Uc= sha1:Mn+cKulVgLVm6kD/5eGi+McjkJc=
X-BSB-Auth 1.93ef626671712550888c.20150514161229BST.87zj572nxe.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:27625

Show key headers only | View raw


jonas.thornvall@gmail.com writes:

> I have this problem with feeding the function in correct order.

The solution is the pass the arrays in the correct order to being with.
I posted about this the last time you asked:

  function doSomething(A, B) {
     return lessThan(A, B) ? reallyDoIt(A, B) : reallyDoIt(B, A);
  }

> This function work great to swap the arrays as long they really are One and Two
>
> ->checkArrayOrder(One,Two) works fine and will swap the arrays if
> arrCompare return true.

That's a terrible name.  A function the determines some property should
be named for the condition it tests.  If a function tests for an even
number, call it 'isEven', not 'checkParity'.  Call a prime tester
'prime' not 'check Divisors', etc.

But here, the function both determines some condition and the acts on
that condition.  It should be called 'swapIfLessThan' (or similar).

> function checkArrayOrder(One,Two)
> {
>    res = arrCompare(One, Two) //Here i check which one bigger smaller

If you used a better name, the comment would be redundant, but even with
the comment I have no idea which way the test goes!

<snip>
> ***But*** i want a more general function to swap any *GLOBAL* arrays?

Stop wanting that!  Manipulating global objects makes for terrible code.

<snip>
-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Swap arrays ones again. jonas.thornvall@gmail.com - 2015-05-14 06:55 -0700
  Re: Swap arrays ones again. jonas.thornvall@gmail.com - 2015-05-14 07:12 -0700
  Re: Swap arrays ones again. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-14 16:12 +0100
    Re: Swap arrays ones again. jonas.thornvall@gmail.com - 2015-05-14 10:17 -0700
      Re: Swap arrays ones again. jonas.thornvall@gmail.com - 2015-05-14 10:47 -0700

csiph-web