Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="description" content="[add your bin description]">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- 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"];
- var numericArr = [0,1,2,4,5,6,7,8,9];
- function combinations(arr, n) {
- var i, j, combs, head, tailcombs;
- if (n > arr.length || n <= 0) {
- return [];
- }
- if (n == arr.length) {
- return [arr];
- }
- if (n == 1) {
- combs = [];
- for (i = 0; i < arr.length; i++) {
- combs.push([arr[i]]);
- }
- return combs;
- }
- combs = [];
- for (i = 0; i < arr.length - n + 1; i++) {
- head = arr.slice(i, i + 1);
- tailcombs = combinations(arr.slice(i + 1), n - 1);
- for (j = 0; j < tailcombs.length; j++) {
- combs.push(head.concat(tailcombs[j]));
- }
- }
- return combs;
- }
- var empty = [];
- var numComb = combinations(numericArr, 3);
- var alphabecticComb = combinations(alphabeticArr, 3);
- for (var x = 0; x <numComb.length; x++){
- for(var y = 0; y < alphabecticComb.length; y++){
- for(var z =0; z <numComb.length; z++){
- empty.push(`${numComb[x]}-${alphabecticComb[y]}-${numComb[z]}`)
- }
- }
- }
- console.log(empty.length);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">
- 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"];
- var numericArr = [0,1,2,4,5,6,7,8,9];
- function combinations(arr, n) {
- var i, j, combs, head, tailcombs;
- if (n > arr.length || n <= 0) {
- return [];
- }
- if (n == arr.length) {
- return [arr];
- }
- if (n == 1) {
- combs = [];
- for (i = 0; i < arr.length; i++) {
- combs.push([arr[i]]);
- }
- return combs;
- }
- combs = [];
- for (i = 0; i < arr.length - n + 1; i++) {
- head = arr.slice(i, i + 1);
- tailcombs = combinations(arr.slice(i + 1), n - 1);
- for (j = 0; j < tailcombs.length; j++) {
- combs.push(head.concat(tailcombs[j]));
- }
- }
- return combs;
- }
- var empty = [];
- var numComb = combinations(numericArr, 3);
- var alphabecticComb = combinations(alphabeticArr, 3);
- for (var x = 0; x <numComb.length; x++){
- for(var y = 0; y < alphabecticComb.length; y++){
- for(var z =0; z <numComb.length; z++){
- empty.push(`${numComb[x]}-${alphabecticComb[y]}-${numComb[z]}`)
- }
- }
- }
- console.log(empty.length);
- </script></body>
- </html>
Add Comment
Please, Sign In to add comment