1
1

Functions.ts 758 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Makes the array a have unique elements.
  3. * WARNING: WILL ALTER THE ARRAY GIVEN
  4. * @param a
  5. */
  6. function arrayUnique(a : Array<any>) {
  7. for(var i=0; i<a.length; ++i) {
  8. for(var j=i+1; j<a.length; ++j) {
  9. if(a[i] === a[j])
  10. a.splice(j--, 1);
  11. }
  12. }
  13. return a;
  14. }
  15. function arrayUniqueNewArray(a : Array<any>) {
  16. a = a.slice();
  17. arrayUnique(a);
  18. return a;
  19. }
  20. function arrayShuffle (a : Array<any>) {
  21. for (let i = 0; i < a.length; i++) {
  22. let pos = Math.floor(Math.random() * (a.length - i)) + i;
  23. let temp = a[i];
  24. a[i] = a[pos];
  25. a[pos] = temp;
  26. }
  27. }
  28. function arrayShuffleNewArray (a : Array<any>) {
  29. let nA = a.slice();
  30. arrayShuffle(nA);
  31. return nA;
  32. }