usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Code for Permutation (Possible Ways of Arrangement) in JavaScript



Permutation - What It Is.

In the unlikely scenario that the Teacher wanted to see just how any four pupils, in a class of six (6), could be seated on a four-person desk; what this Teacher would be doing in essence is called Permutation (nPr).



Code for Doing Permutation in JavaScript

The algorithm for Permutation - nPr, possible ways of arrangement - will simply be based on that of combination.

All that is needed after combination is a rotation / shuffle of the make-up / constituents of each possible combination result.

This shuffle simply involves interchanging the elements of the combination group of size, r, to take all possible positions starting from the extreme right to extreme left.

This is how our Permutation code in JavaScript will work.

Create 2 new files; On Notepad++: File, New.
Call them Permutation.html and Permutation.js respectively.
Type out the adjoining JavaScript code for Permutation (nPr).



Advice: You might want to keep the mother-class size (n) and the group-size (r) small to avoid the permutation code taking too long.
As a rule-of-thump, DO NOT ASK QUESTIONS YOU DON'T WANT TO KNOW THE ANSWER TO.









<< PreviousNext >>