|Subject:||2Q : Condensing an array; how random works.|
|Posted by:||Dr John Stockton (firstname.lastname@example.org)|
|Date:||Sun, 13 Jul 2003|
Given an array such as might have been generated by
var A = [,,2,,,,4,,,6,,,8,,,]
is there a highly effective way of reducing it to [2,4,6,8] - i.e.
removing the undefineds and shifting the rest down?
A.sort().slice(0,n) // would do it, but sorts; and the number
of active elements must be known.
I know, of course, about explicitly looping through all of A and testing
A.join('#').split(/#+/) // looks inefficient
Is anything exact known about the internal mechanism of Math.random() ?
Do later browsers provide access to the seed value?
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URLhttp://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URLhttp://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URLhttp://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.