Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getPerm(A, good)
- {
- while (true)
- {
- wrong = 0;
- console.log(A);
- notA = A.map(x => x == good ? wrong : good);
- lIndex = A.lastIndexOf(good);
- if (lIndex != A.length - 1)
- {
- temp = A[lIndex];
- A[lIndex]=A[lIndex+1];
- A[lIndex+1]=temp;
- }
- else
- {
- lIndex0 = notA.lastIndexOf(good);
- tIndex1 = A.lastIndexOf(good, lIndex0);
- if (tIndex1 == -1 || lIndex0 == -1)
- break;
- else
- {
- A[tIndex1] = wrong;
- A[tIndex1+1] = good;
- for (let i=1; i<A.length - lIndex0; ++i)
- {
- temp= A[tIndex1+i+1];
- A[tIndex1+i+1] = A[lIndex0+i];
- A[lIndex0+i] = temp;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement