Skip to content

Commit 5f6e1c4

Browse files
committed
Add docs
1 parent 312a265 commit 5f6e1c4

8 files changed

+1484
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JSDoc: Source: combinatorics/cartesianproduct.js</title>
6+
7+
<script src="scripts/prettify/prettify.js"> </script>
8+
<script src="scripts/prettify/lang-css.js"> </script>
9+
<!--[if lt IE 9]>
10+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11+
<![endif]-->
12+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14+
</head>
15+
16+
<body>
17+
18+
<div id="main">
19+
20+
<h1 class="page-title">Source: combinatorics/cartesianproduct.js</h1>
21+
22+
23+
24+
25+
26+
27+
<section>
28+
<article>
29+
<pre class="prettyprint source linenums"><code>(function (exports) {
30+
'use strict';
31+
32+
var cartesianProduct = (function () {
33+
var result;
34+
35+
function cartesianProduct(sets, index, current) {
36+
if (index === sets.length) {
37+
return result.push(current.slice());
38+
}
39+
for (var i = 0; i &lt; sets[index].length; i += 1) {
40+
current[index] = sets[index][i];
41+
cartesianProduct(sets, index + 1, current);
42+
}
43+
}
44+
45+
/**
46+
* Calculates Cartesian product of provided sets.
47+
*
48+
* @module combinatorics/cartesianproduct
49+
* @public
50+
* @param {Array} sets Array of sets.
51+
* @return {Array} Cartesian product of provided sets.
52+
*
53+
* @example
54+
* var product = require('path-to-algorithms/src/combinatorics/' +
55+
* 'cartesianproduct').cartesianProduct;
56+
* var result = product([[1, 2, 3], [3, 2, 1]]);
57+
* // [ [ 1, 3 ],
58+
* // [ 1, 2 ],
59+
* // [ 1, 1 ],
60+
* // [ 2, 3 ],
61+
* // [ 2, 2 ],
62+
* // [ 2, 1 ],
63+
* // [ 3, 3 ],
64+
* // [ 3, 2 ],
65+
* // [ 3, 1 ] ]
66+
* console.log(result);
67+
*/
68+
return function (sets) {
69+
result = [];
70+
cartesianProduct(sets, 0, []);
71+
return result;
72+
};
73+
}());
74+
75+
exports.cartesianProduct = cartesianProduct;
76+
77+
}((typeof window === 'undefined') ? module.exports : window));
78+
</code></pre>
79+
</article>
80+
</section>
81+
82+
83+
84+
85+
</div>
86+
87+
<nav>
88+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-combinatorics_cartesianproduct.html">combinatorics/cartesianproduct</a></li><li><a href="module-combinatorics_combinations.html">combinatorics/combinations</a></li><li><a href="module-combinatorics_permutations.html">combinatorics/permutations</a></li><li><a href="module-combinatorics_variations-repetition.html">combinatorics/variations-repetition</a></li><li><a href="module-data-structures_binary-search-tree.html">data-structures/binary-search-tree</a></li><li><a href="module-data-structures_heap.html">data-structures/heap</a></li><li><a href="module-data-structures_interval-tree.html">data-structures/interval-tree</a></li><li><a href="module-data-structures_linked-list.html">data-structures/linked-list</a></li><li><a href="module-data-structures_red-black-tree.html">data-structures/red-black-tree</a></li><li><a href="module-graphs_others_topological-sort.html">graphs/others/topological-sort</a></li><li><a href="module-graphs_searching_bfs.html">graphs/searching/bfs</a></li><li><a href="module-graphs_searching_dfs.html">graphs/searching/dfs</a></li><li><a href="module-graphs_shortest-path_bellman-ford.html">graphs/shortest-path/bellman-ford</a></li><li><a href="module-graphs_shortest-path_dijkstra.html">graphs/shortest-path/dijkstra</a></li><li><a href="module-graphs_shortest-path_floyd-warshall.html">graphs/shortest-path/floyd-warshall</a></li><li><a href="module-graphs_spanning-trees_prim.html">graphs/spanning-trees/prim</a></li><li><a href="module-primes_is-prime.html">primes/is-prime</a></li><li><a href="module-primes_prime-factor-tree.html">primes/prime-factor-tree</a></li><li><a href="module-primes_sieve-of-eratosthenes.html">primes/sieve-of-eratosthenes</a></li></ul><h3>Classes</h3><ul><li><a href="module-data-structures_binary-search-tree.BinaryTree.html">BinaryTree</a></li><li><a href="module-data-structures_binary-search-tree.Node.html">Node</a></li><li><a href="module-data-structures_heap.Heap.html">Heap</a></li><li><a href="module-data-structures_interval-tree.IntervalTree.html">IntervalTree</a></li><li><a href="module-data-structures_interval-tree.Node.html">Node</a></li><li><a href="module-data-structures_linked-list.LinkedList.html">LinkedList</a></li><li><a href="module-data-structures_linked-list.Node.html">Node</a></li><li><a href="module-data-structures_red-black-tree.RBTree.html">RBTree</a></li><li><a href="module-graphs_shortest-path_bellman-ford.Edge.html">Edge</a></li><li><a href="module-graphs_spanning-trees_prim.Edge.html">Edge</a></li><li><a href="module-graphs_spanning-trees_prim.Graph.html">Graph</a></li><li><a href="module-graphs_spanning-trees_prim.Vertex.html">Vertex</a></li></ul>
89+
</nav>
90+
91+
<br class="clear">
92+
93+
<footer>
94+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha13</a> on Sun Jan 11 2015 20:12:49 GMT+0200 (EET)
95+
</footer>
96+
97+
<script> prettyPrint(); </script>
98+
<script src="scripts/linenumber.js"> </script>
99+
</body>
100+
</html>

combinatorics_combinations.js.html

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JSDoc: Source: combinatorics/combinations.js</title>
6+
7+
<script src="scripts/prettify/prettify.js"> </script>
8+
<script src="scripts/prettify/lang-css.js"> </script>
9+
<!--[if lt IE 9]>
10+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11+
<![endif]-->
12+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14+
</head>
15+
16+
<body>
17+
18+
<div id="main">
19+
20+
<h1 class="page-title">Source: combinatorics/combinations.js</h1>
21+
22+
23+
24+
25+
26+
27+
<section>
28+
<article>
29+
<pre class="prettyprint source linenums"><code>(function (exports) {
30+
'use strict';
31+
32+
var combinations = (function () {
33+
var res = [];
34+
35+
function combinations(arr, k, start, idx, current) {
36+
if (idx === k) {
37+
res.push(current.slice());
38+
return;
39+
}
40+
for (var i = start; i &lt; arr.length; i += 1) {
41+
current[idx] = arr[i];
42+
combinations(arr, k, i + 1, idx + 1, current);
43+
}
44+
}
45+
46+
/**
47+
* Finds all the combinations of given array.&lt;br>&lt;br>
48+
* A combination is a way of selecting members from a grouping,
49+
* such that (unlike permutations) the order of selection does not matter.
50+
* For example given three fruits, say an apple, an orange and a pear,
51+
* there are three combinations of two that can be drawn from this set:
52+
* an apple and a pear; an apple and an orange; or a pear and an orange.
53+
*
54+
* @example
55+
*
56+
* var combinations = require('path-to-algorithms/src/' +
57+
* 'combinatorics/combinations').combinations;
58+
* var result = combinations(['apple', 'orange', 'pear'], 2);
59+
* // [['apple', 'orange'],
60+
* // ['apple', 'pear'],
61+
* // ['orange', 'pear']]
62+
* console.log(result);
63+
*
64+
* @module combinatorics/combinations
65+
* @public
66+
* @param arr {Array} Set of items.
67+
* @param k {Number} Size of each combination.
68+
* @return {Array} Returns all combinations.
69+
*/
70+
return function (arr, k) {
71+
res = [];
72+
combinations(arr, k, 0, 0, []);
73+
var temp = res;
74+
// Free the extra memory
75+
res = null;
76+
return temp;
77+
};
78+
}());
79+
80+
exports.combinations = combinations;
81+
82+
}((typeof window === 'undefined') ? module.exports : window));
83+
</code></pre>
84+
</article>
85+
</section>
86+
87+
88+
89+
90+
</div>
91+
92+
<nav>
93+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-combinatorics_cartesianproduct.html">combinatorics/cartesianproduct</a></li><li><a href="module-combinatorics_combinations.html">combinatorics/combinations</a></li><li><a href="module-combinatorics_permutations.html">combinatorics/permutations</a></li><li><a href="module-combinatorics_variations-repetition.html">combinatorics/variations-repetition</a></li><li><a href="module-data-structures_binary-search-tree.html">data-structures/binary-search-tree</a></li><li><a href="module-data-structures_heap.html">data-structures/heap</a></li><li><a href="module-data-structures_interval-tree.html">data-structures/interval-tree</a></li><li><a href="module-data-structures_linked-list.html">data-structures/linked-list</a></li><li><a href="module-data-structures_red-black-tree.html">data-structures/red-black-tree</a></li><li><a href="module-graphs_others_topological-sort.html">graphs/others/topological-sort</a></li><li><a href="module-graphs_searching_bfs.html">graphs/searching/bfs</a></li><li><a href="module-graphs_searching_dfs.html">graphs/searching/dfs</a></li><li><a href="module-graphs_shortest-path_bellman-ford.html">graphs/shortest-path/bellman-ford</a></li><li><a href="module-graphs_shortest-path_dijkstra.html">graphs/shortest-path/dijkstra</a></li><li><a href="module-graphs_shortest-path_floyd-warshall.html">graphs/shortest-path/floyd-warshall</a></li><li><a href="module-graphs_spanning-trees_prim.html">graphs/spanning-trees/prim</a></li><li><a href="module-primes_is-prime.html">primes/is-prime</a></li><li><a href="module-primes_prime-factor-tree.html">primes/prime-factor-tree</a></li><li><a href="module-primes_sieve-of-eratosthenes.html">primes/sieve-of-eratosthenes</a></li></ul><h3>Classes</h3><ul><li><a href="module-data-structures_binary-search-tree.BinaryTree.html">BinaryTree</a></li><li><a href="module-data-structures_binary-search-tree.Node.html">Node</a></li><li><a href="module-data-structures_heap.Heap.html">Heap</a></li><li><a href="module-data-structures_interval-tree.IntervalTree.html">IntervalTree</a></li><li><a href="module-data-structures_interval-tree.Node.html">Node</a></li><li><a href="module-data-structures_linked-list.LinkedList.html">LinkedList</a></li><li><a href="module-data-structures_linked-list.Node.html">Node</a></li><li><a href="module-data-structures_red-black-tree.RBTree.html">RBTree</a></li><li><a href="module-graphs_shortest-path_bellman-ford.Edge.html">Edge</a></li><li><a href="module-graphs_spanning-trees_prim.Edge.html">Edge</a></li><li><a href="module-graphs_spanning-trees_prim.Graph.html">Graph</a></li><li><a href="module-graphs_spanning-trees_prim.Vertex.html">Vertex</a></li></ul>
94+
</nav>
95+
96+
<br class="clear">
97+
98+
<footer>
99+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha13</a> on Sun Jan 11 2015 20:12:49 GMT+0200 (EET)
100+
</footer>
101+
102+
<script> prettyPrint(); </script>
103+
<script src="scripts/linenumber.js"> </script>
104+
</body>
105+
</html>

combinatorics_permutations.js.html

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JSDoc: Source: combinatorics/permutations.js</title>
6+
7+
<script src="scripts/prettify/prettify.js"> </script>
8+
<script src="scripts/prettify/lang-css.js"> </script>
9+
<!--[if lt IE 9]>
10+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11+
<![endif]-->
12+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14+
</head>
15+
16+
<body>
17+
18+
<div id="main">
19+
20+
<h1 class="page-title">Source: combinatorics/permutations.js</h1>
21+
22+
23+
24+
25+
26+
27+
<section>
28+
<article>
29+
<pre class="prettyprint source linenums"><code>(function (exports) {
30+
'use strict';
31+
var permutations = (function () {
32+
33+
var res;
34+
35+
function swap(arr, i, j) {
36+
var temp = arr[i];
37+
arr[i] = arr[j];
38+
arr[j] = temp;
39+
}
40+
41+
function permutations(arr, current) {
42+
if (current >= arr.length) {
43+
return res.push(arr.slice());
44+
}
45+
for (var i = current; i &lt; arr.length; i += 1) {
46+
swap(arr, i, current);
47+
permutations(arr, current + 1);
48+
swap(arr, i, current);
49+
}
50+
}
51+
52+
/**
53+
* Finds all the permutations of given array.&lt;br>&lt;br>
54+
* Permutation relates to the act of rearranging, or permuting,
55+
* all the members of a set into some sequence or order.
56+
* For example there are six permutations of the set {1,2,3}, namely:
57+
* (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1).&lt;br>&lt;br>
58+
* Complexity: O(N*N!).
59+
*
60+
* @example
61+
*
62+
* var permutations = require('path-to-algorithms/src/' +
63+
* 'combinatorics/permutations').permutations;
64+
* var result = permutations(['apple', 'orange', 'pear']);
65+
*
66+
* // [ [ 'apple', 'orange', 'pear' ],
67+
* // [ 'apple', 'pear', 'orange' ],
68+
* // [ 'orange', 'apple', 'pear' ],
69+
* // [ 'orange', 'pear', 'apple' ],
70+
* // [ 'pear', 'orange', 'apple' ],
71+
* // [ 'pear', 'apple', 'orange' ] ]
72+
* console.log(result);
73+
*
74+
* @module combinatorics/permutations
75+
* @public
76+
* @param {Array} arr Array to find the permutations of.
77+
* @param {Number} current Current element.
78+
* @returns {Array} Array containing all the permutations.
79+
*/
80+
return function (arr) {
81+
res = [];
82+
permutations(arr, 0);
83+
var temp = res;
84+
// Free the extra memory
85+
res = null;
86+
return temp;
87+
};
88+
}());
89+
90+
exports.permutations = permutations;
91+
92+
}((typeof window === 'undefined') ? module.exports : window));
93+
</code></pre>
94+
</article>
95+
</section>
96+
97+
98+
99+
100+
</div>
101+
102+
<nav>
103+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-combinatorics_cartesianproduct.html">combinatorics/cartesianproduct</a></li><li><a href="module-combinatorics_combinations.html">combinatorics/combinations</a></li><li><a href="module-combinatorics_permutations.html">combinatorics/permutations</a></li><li><a href="module-combinatorics_variations-repetition.html">combinatorics/variations-repetition</a></li><li><a href="module-data-structures_binary-search-tree.html">data-structures/binary-search-tree</a></li><li><a href="module-data-structures_heap.html">data-structures/heap</a></li><li><a href="module-data-structures_interval-tree.html">data-structures/interval-tree</a></li><li><a href="module-data-structures_linked-list.html">data-structures/linked-list</a></li><li><a href="module-data-structures_red-black-tree.html">data-structures/red-black-tree</a></li><li><a href="module-graphs_others_topological-sort.html">graphs/others/topological-sort</a></li><li><a href="module-graphs_searching_bfs.html">graphs/searching/bfs</a></li><li><a href="module-graphs_searching_dfs.html">graphs/searching/dfs</a></li><li><a href="module-graphs_shortest-path_bellman-ford.html">graphs/shortest-path/bellman-ford</a></li><li><a href="module-graphs_shortest-path_dijkstra.html">graphs/shortest-path/dijkstra</a></li><li><a href="module-graphs_shortest-path_floyd-warshall.html">graphs/shortest-path/floyd-warshall</a></li><li><a href="module-graphs_spanning-trees_prim.html">graphs/spanning-trees/prim</a></li><li><a href="module-primes_is-prime.html">primes/is-prime</a></li><li><a href="module-primes_prime-factor-tree.html">primes/prime-factor-tree</a></li><li><a href="module-primes_sieve-of-eratosthenes.html">primes/sieve-of-eratosthenes</a></li></ul><h3>Classes</h3><ul><li><a href="module-data-structures_binary-search-tree.BinaryTree.html">BinaryTree</a></li><li><a href="module-data-structures_binary-search-tree.Node.html">Node</a></li><li><a href="module-data-structures_heap.Heap.html">Heap</a></li><li><a href="module-data-structures_interval-tree.IntervalTree.html">IntervalTree</a></li><li><a href="module-data-structures_interval-tree.Node.html">Node</a></li><li><a href="module-data-structures_linked-list.LinkedList.html">LinkedList</a></li><li><a href="module-data-structures_linked-list.Node.html">Node</a></li><li><a href="module-data-structures_red-black-tree.RBTree.html">RBTree</a></li><li><a href="module-graphs_shortest-path_bellman-ford.Edge.html">Edge</a></li><li><a href="module-graphs_spanning-trees_prim.Edge.html">Edge</a></li><li><a href="module-graphs_spanning-trees_prim.Graph.html">Graph</a></li><li><a href="module-graphs_spanning-trees_prim.Vertex.html">Vertex</a></li></ul>
104+
</nav>
105+
106+
<br class="clear">
107+
108+
<footer>
109+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha13</a> on Sun Jan 11 2015 20:12:49 GMT+0200 (EET)
110+
</footer>
111+
112+
<script> prettyPrint(); </script>
113+
<script src="scripts/linenumber.js"> </script>
114+
</body>
115+
</html>

0 commit comments

Comments
 (0)