Guest User

Untitled

a guest
Mar 21st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="[add your bin description]">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>JS Bin</title>
  8. </head>
  9. <body>
  10.  
  11. <script id="jsbin-javascript">
  12. var alphabeticArr = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  13. var numericArr = [0,1,2,4,5,6,7,8,9];
  14.  
  15.  
  16.  
  17.  
  18. function combinations(arr, n) {
  19. var i, j, combs, head, tailcombs;
  20.  
  21.  
  22. if (n > arr.length || n <= 0) {
  23. return [];
  24. }
  25.  
  26.  
  27. if (n == arr.length) {
  28. return [arr];
  29. }
  30.  
  31.  
  32. if (n == 1) {
  33. combs = [];
  34. for (i = 0; i < arr.length; i++) {
  35. combs.push([arr[i]]);
  36. }
  37. return combs;
  38. }
  39.  
  40. combs = [];
  41. for (i = 0; i < arr.length - n + 1; i++) {
  42. head = arr.slice(i, i + 1);
  43. tailcombs = combinations(arr.slice(i + 1), n - 1);
  44.  
  45. for (j = 0; j < tailcombs.length; j++) {
  46. combs.push(head.concat(tailcombs[j]));
  47. }
  48. }
  49. return combs;
  50. }
  51.  
  52.  
  53. var empty = [];
  54. var numComb = combinations(numericArr, 3);
  55. var alphabecticComb = combinations(alphabeticArr, 3);
  56.  
  57. for (var x = 0; x <numComb.length; x++){
  58. for(var y = 0; y < alphabecticComb.length; y++){
  59. for(var z =0; z <numComb.length; z++){
  60. empty.push(`${numComb[x]}-${alphabecticComb[y]}-${numComb[z]}`)
  61. }
  62. }
  63. }
  64.  
  65. console.log(empty.length);
  66. </script>
  67.  
  68.  
  69.  
  70. <script id="jsbin-source-javascript" type="text/javascript">
  71.  
  72.  
  73. var alphabeticArr = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  74. var numericArr = [0,1,2,4,5,6,7,8,9];
  75.  
  76.  
  77.  
  78.  
  79. function combinations(arr, n) {
  80. var i, j, combs, head, tailcombs;
  81.  
  82.  
  83. if (n > arr.length || n <= 0) {
  84. return [];
  85. }
  86.  
  87.  
  88. if (n == arr.length) {
  89. return [arr];
  90. }
  91.  
  92.  
  93. if (n == 1) {
  94. combs = [];
  95. for (i = 0; i < arr.length; i++) {
  96. combs.push([arr[i]]);
  97. }
  98. return combs;
  99. }
  100.  
  101. combs = [];
  102. for (i = 0; i < arr.length - n + 1; i++) {
  103. head = arr.slice(i, i + 1);
  104. tailcombs = combinations(arr.slice(i + 1), n - 1);
  105.  
  106. for (j = 0; j < tailcombs.length; j++) {
  107. combs.push(head.concat(tailcombs[j]));
  108. }
  109. }
  110. return combs;
  111. }
  112.  
  113.  
  114. var empty = [];
  115. var numComb = combinations(numericArr, 3);
  116. var alphabecticComb = combinations(alphabeticArr, 3);
  117.  
  118. for (var x = 0; x <numComb.length; x++){
  119. for(var y = 0; y < alphabecticComb.length; y++){
  120. for(var z =0; z <numComb.length; z++){
  121. empty.push(`${numComb[x]}-${alphabecticComb[y]}-${numComb[z]}`)
  122. }
  123. }
  124. }
  125.  
  126. console.log(empty.length);
  127. </script></body>
  128. </html>
Add Comment
Please, Sign In to add comment