From: Dr J R Stockton on
In comp.lang.javascript message <7huc6cb0.fsf(a)gmail.com>, Fri, 30 Oct
2009 18:06:59, Lasse Reichstein Nielsen <lrn.unread(a)gmail.com> posted:
>
>Indeed. The "algorithm" is:
> list = list.sort(function() Math.random() - 0.5)
>

> ...

A smarter TC39 would have realised that shuffling is commonly badly
done, and therefore introduced SHUFFLE (and DEAL and DRAW) as new
methods of Array. Since they can be coded briefly and efficiently in
Pascal and JavaScript (using Random(N) [*]), there should be no
difficulty in doing likewise in JavaScript engine source code.

[*] <URL:http://www.merlyn.demon.co.uk/js-randm.htm>

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
From: "Michael Haufe ("TNO")" on
On Oct 29, 4:03 pm, Jorge <jo...(a)jorgechamorro.com> wrote:
> http://code.google.com/p/jslibs/wiki/JavascriptTips
....
> Floating to integer
> (123.345456).toFixed(); // is: 123
> typeof (1.5).toFixed(); // is: string

You could do this as a faster alternative:

~~123.345456
From: abozhilov on
On 31 ïËÔ, 23:11, "Michael Haufe (\"TNO\")" <t...(a)thenewobjective.com>
wrote:

> You could do this as a faster alternative:
>
> ~~123.345456

In Ecma262 Number is double-precision 64-bit format IEEE 754. You
missed one general point. Bitwise operators cast Number to ToInt32();
So you can overflow 32 bits, and get unexpected results.

Math.floor(123.345456); //123
123.345456 - (123.345456 % 1); //123

Regards.
From: Asen Bozhilov on
On 29 Окт, 23:03, Jorge <jo...(a)jorgechamorro.com> wrote:
> http://code.google.com/p/jslibs/wiki/JavascriptTips
>
> --
> Jorge.

| function isNotEmpty(obj) {
| for ( var tmp in obj )
| return true
| }

What are you mean with that function "isNotEmpty"? For-in look up in
prototype chain and enumerate properties who's doesn't have attribute
{DontEnum}. In ECMA262 i don't know `object' who is empty, because
inherit from Object.prototype.

| Insert an array in another array
| var a = [1,2,3,4,5,6]
| var b = ['a','b','c']
| var insertIndex = 5;
| Array.concat( a.splice( 0, insertIndex ), b, a )

`splice' modified properties of `object' who refer `a'. See topic of
Csaba Gabor:
<URL:http://groups.google.com/group/comp.lang.javascript/browse_thread/
thread/ec2ffbc979c65cc4/ebc7570a2f3ea7aa?pli=1>

Regards/

From: "Michael Haufe ("TNO")" on
On Oct 31, 4:40 pm, abozhilov <fort...(a)gmail.com> wrote:
> On 31 ïËÔ, 23:11, "Michael Haufe (\"TNO\")" <t...(a)thenewobjective.com>
> wrote:
>
> > You could do this as a faster alternative:
>
> > ~~123.345456
>
> In Ecma262 Number is double-precision 64-bit format IEEE 754. You
> missed one general point. Bitwise operators cast Number to ToInt32();
> So you can overflow 32 bits, and get unexpected results.
>
> Math.floor(123.345456); //123
> 123.345456 - (123.345456 % 1); //123
>
> Regards.

Good catch.