Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Generating all combinations of array using javascript

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 08-16-2013, 04:22 PM PM User | #1 jscriptuser New Coder   Join Date: Aug 2013 Posts: 12 Thanks: 0 Thanked 0 Times in 0 Posts Generating all combinations of array using javascript Hello Jscript Developers How can I generate all possible combinations of an array using javascript. For Ex: 1234 Combinations required: 1234 1324 1432 .... .... 4213 4321 and also I want to generate combinations based on factorial .For 7! we have to loop 720 times .is it any problem running such loops from client side Thanks and regards Muralikrishna
 08-16-2013, 05:31 PM PM User | #2 007julien Regular Coder   Join Date: May 2012 Location: France Posts: 174 Thanks: 0 Thanked 27 Times in 25 Posts This page gives all permutations off n numbers. Its uses only the first function getPrm (the second is getNmb) to get the permutation with is factorial number (or this number with the permutation). See wikipedia Factorial_number_system for further explanations. Code: ```

Permutations

``` To find the 15 th permutation of 1234 (from 0 to 23) 1/ - divide 15 by 3!=6 witch is 2 => to take the number of rank 2 of '1234' witch is '3' 2/ - divide the rest by 2!=2 witch is 1 => to take the number of rank 1 of '124' witch is '2' =>'32' 3/ - divide the rest by 1!=1 witch is 1 => to take take the number of rank 1 of '14' witch is '4' =>'324' 4/ - divide the rest by 0!=1 witch is 0 => to take take the number of rank 0 of '1' witch is '1' =>'3241' With this functions there is no need to calculate all permutation to find one (or inversely)... Last edited by 007julien; 08-16-2013 at 07:47 PM..
 08-16-2013, 05:32 PM PM User | #3 Philip M Supreme Master coder!     Join Date: Jun 2002 Location: London, England Posts: 17,478 Thanks: 200 Thanked 2,470 Times in 2,448 Posts Here you are:- Code: `````` 720 loops ought not to be a problem. 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040 6! is 720. But do you mean combinations or permutations? Quizmaster: What animals do you associate with gymkhanas? Contestant: Elephants __________________ All the code given in this post has been tested and is intended to address the question asked. Unless stated otherwise it is not just a demonstration. Last edited by Philip M; 08-16-2013 at 06:53 PM..

 Bookmarks

 Tags jscript

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 09:50 PM.