From: Dr J R Stockton on 31 Oct 2009 12:25 In comp.lang.javascript message <7huc6cb0.fsf(a)gmail.com>, Fri, 30 Oct 2009 18:06:59, Lasse Reichstein Nielsen 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. [*] -- (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3 news:comp.lang.javascript FAQ . jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links. From: "Michael Haufe ("TNO")" on 31 Oct 2009 17:11 On Oct 29, 4:03 pm, Jorge 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 31 Oct 2009 17:40 On 31 ïËÔ, 23:11, "Michael Haufe (\"TNO\")" 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 31 Oct 2009 18:15 On 29 ÐÐºÑ, 23:03, Jorge 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: Regards/ From: "Michael Haufe ("TNO")" on 31 Oct 2009 18:44 On Oct 31, 4:40 pm, abozhilov wrote:> On 31 ïËÔ, 23:11, "Michael Haufe (\"TNO\")" > 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. First  |  Prev  |  Next  |  Last Pages: 1 2 3 4 Prev: Creating an Object that extends Array functionalityNext: Limit of 4K