Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function getPerm(A, good)
  2. {
  3. while (true)
  4. {
  5. wrong = 0;
  6. console.log(A);
  7. notA = A.map(x => x == good ? wrong : good);
  8.  
  9. lIndex = A.lastIndexOf(good);
  10. if (lIndex != A.length - 1)
  11. {
  12. temp = A[lIndex];
  13. A[lIndex]=A[lIndex+1];
  14. A[lIndex+1]=temp;
  15. }
  16. else
  17. {
  18. lIndex0 = notA.lastIndexOf(good);
  19. tIndex1 = A.lastIndexOf(good, lIndex0);
  20. if (tIndex1 == -1 || lIndex0 == -1)
  21. break;
  22. else
  23. {
  24. A[tIndex1] = wrong;
  25. A[tIndex1+1] = good;
  26. for (let i=1; i<A.length - lIndex0; ++i)
  27. {
  28. temp= A[tIndex1+i+1];
  29. A[tIndex1+i+1] = A[lIndex0+i];
  30. A[lIndex0+i] = temp;
  31. }
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement