Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27625
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Swap arrays ones again. |
| Date | 2015-05-14 16:12 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87zj572nxe.fsf@bsb.me.uk> (permalink) |
| References | <974af16e-3a67-4d6c-944a-af27660f05a8@googlegroups.com> |
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
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