From fe72e727205c6fcf72664b1013f3240f58d2441e Mon Sep 17 00:00:00 2001 From: Pavlo Voznenko Date: Sun, 11 Jan 2015 17:33:19 +0100 Subject: [PATCH] added documentation for primes --- data-structures_binary-search-tree.js.html | 7 +- data-structures_heap.js.html | 7 +- data-structures_interval-tree.js.html | 15 +- data-structures_linked-list.js.html | 7 +- data-structures_red-black-tree.js.html | 7 +- graphs_others_topological-sort.js.html | 4 +- graphs_searching_bfs.js.html | 7 +- graphs_searching_dfs.js.html | 7 +- graphs_shortest-path_bellman-ford.js.html | 7 +- graphs_shortest-path_dijkstra.js.html | 7 +- graphs_shortest-path_floyd-warshall.js.html | 4 +- graphs_spanning-trees_prim.js.html | 7 +- index.html | 4 +- ...uctures_binary-search-tree.BinaryTree.html | 4 +- ...ta-structures_binary-search-tree.Node.html | 4 +- ...le-data-structures_binary-search-tree.html | 4 +- module-data-structures_heap.Heap.html | 4 +- module-data-structures_heap.html | 4 +- ...structures_interval-tree.IntervalTree.html | 4 +- ...le-data-structures_interval-tree.Node.html | 4 +- module-data-structures_interval-tree.html | 4 +- ...ata-structures_linked-list.LinkedList.html | 4 +- module-data-structures_linked-list.Node.html | 4 +- module-data-structures_linked-list.html | 4 +- ...data-structures_red-black-tree.RBTree.html | 4 +- module-data-structures_red-black-tree.html | 4 +- module-graphs_others_topological-sort.html | 4 +- module-graphs_searching_bfs.html | 4 +- module-graphs_searching_dfs.html | 4 +- ...raphs_shortest-path_bellman-ford.Edge.html | 4 +- module-graphs_shortest-path_bellman-ford.html | 4 +- module-graphs_shortest-path_dijkstra.html | 4 +- ...e-graphs_shortest-path_floyd-warshall.html | 4 +- module-graphs_spanning-trees_prim.Edge.html | 4 +- module-graphs_spanning-trees_prim.Graph.html | 4 +- module-graphs_spanning-trees_prim.Vertex.html | 4 +- module-graphs_spanning-trees_prim.html | 4 +- module-primes.html | 234 +++++++++++++++++ module-primes_is-prime.html | 238 +++++++++++++++++ module-primes_prime-factor-tree.html | 240 +++++++++++++++++ module-primes_sieve-of-eratosthenes.html | 246 ++++++++++++++++++ primes_is-prime.js.html | 112 ++++++++ primes_prime-factor-tree.js.html | 88 +++++++ primes_sieve-of-eratosthenes.js.html | 106 ++++++++ 44 files changed, 1362 insertions(+), 88 deletions(-) create mode 100644 module-primes.html create mode 100644 module-primes_is-prime.html create mode 100644 module-primes_prime-factor-tree.html create mode 100644 module-primes_sieve-of-eratosthenes.html create mode 100644 primes_is-prime.js.html create mode 100644 primes_prime-factor-tree.js.html create mode 100644 primes_sieve-of-eratosthenes.js.html diff --git a/data-structures_binary-search-tree.js.html b/data-structures_binary-search-tree.js.html index 3d2861c1..34d425cf 100644 --- a/data-structures_binary-search-tree.js.html +++ b/data-structures_binary-search-tree.js.html @@ -457,7 +457,8 @@

Source: data-structures/binary-search-tree.js

this._existsInSubtree(node, root._right); }; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -467,13 +468,13 @@

Source: data-structures/binary-search-tree.js


diff --git a/data-structures_heap.js.html b/data-structures_heap.js.html index 10d574a0..800063f7 100644 --- a/data-structures_heap.js.html +++ b/data-structures_heap.js.html @@ -218,7 +218,8 @@

Source: data-structures/heap.js

return !this._heap.length; }; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -228,13 +229,13 @@

Source: data-structures/heap.js


diff --git a/data-structures_interval-tree.js.html b/data-structures_interval-tree.js.html index 6db19816..26f36d6a 100644 --- a/data-structures_interval-tree.js.html +++ b/data-structures_interval-tree.js.html @@ -60,7 +60,7 @@

Source: data-structures/interval-tree.js

* @param {Node} left Left child node. * @param {Node} right Right child node. */ - exports.Node = function(start, end, left, right) { + exports.Node = function (start, end, left, right) { /** * Node interval. * @member {Array} @@ -74,7 +74,7 @@

Source: data-structures/interval-tree.js

/** * Parent node. * @member {Node} - */ + */ this.parentNode = null; /** * Left child node. @@ -94,7 +94,7 @@

Source: data-structures/interval-tree.js

* @public * @constructor */ - exports.IntervalTree = function() { + exports.IntervalTree = function () { /** * Root node of the tree. * @member {Node} @@ -323,7 +323,7 @@

Source: data-structures/interval-tree.js

/** * Remove interval from the tree. - * + * * @public * @method * @param {Array} intreval Array with start and end of the interval. @@ -332,7 +332,8 @@

Source: data-structures/interval-tree.js

return this._removeHelper(interval, this.root); }; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -342,13 +343,13 @@

Source: data-structures/interval-tree.js


diff --git a/data-structures_linked-list.js.html b/data-structures_linked-list.js.html index 8e705108..1389f1a3 100644 --- a/data-structures_linked-list.js.html +++ b/data-structures_linked-list.js.html @@ -290,7 +290,8 @@

Source: data-structures/linked-list.js

this.last = temp; }; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -300,13 +301,13 @@

Source: data-structures/linked-list.js


diff --git a/data-structures_red-black-tree.js.html b/data-structures_red-black-tree.js.html index a915519f..373544cd 100644 --- a/data-structures_red-black-tree.js.html +++ b/data-structures_red-black-tree.js.html @@ -294,7 +294,8 @@

Source: data-structures/red-black-tree.js

} }; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -304,13 +305,13 @@

Source: data-structures/red-black-tree.js


diff --git a/graphs_others_topological-sort.js.html b/graphs_others_topological-sort.js.html index 7cdd6867..910915e0 100644 --- a/graphs_others_topological-sort.js.html +++ b/graphs_others_topological-sort.js.html @@ -96,13 +96,13 @@

Source: graphs/others/topological-sort.js


diff --git a/graphs_searching_bfs.js.html b/graphs_searching_bfs.js.html index 9281dc67..16a4c62f 100644 --- a/graphs_searching_bfs.js.html +++ b/graphs_searching_bfs.js.html @@ -89,7 +89,8 @@

Source: graphs/searching/bfs.js

exports.bfs = bfs; -}((typeof window === 'undefined') ? module.exports : window)); +}((typeof window === 'undefined') ? module.exports : window)); + @@ -99,13 +100,13 @@

Source: graphs/searching/bfs.js


diff --git a/graphs_searching_dfs.js.html b/graphs_searching_dfs.js.html index 582af0ef..4389c613 100644 --- a/graphs_searching_dfs.js.html +++ b/graphs_searching_dfs.js.html @@ -81,7 +81,8 @@

Source: graphs/searching/dfs.js

exports.dfs = dfs; -}(typeof exports === 'undefined' ? window : exports)); +}(typeof exports === 'undefined' ? window : exports)); + @@ -91,13 +92,13 @@

Source: graphs/searching/dfs.js


diff --git a/graphs_shortest-path_bellman-ford.js.html b/graphs_shortest-path_bellman-ford.js.html index 246abaf1..3c6e9875 100644 --- a/graphs_shortest-path_bellman-ford.js.html +++ b/graphs_shortest-path_bellman-ford.js.html @@ -116,7 +116,8 @@

Source: graphs/shortest-path/bellman-ford.js

return { parents: parents, distances: distances }; }; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -126,13 +127,13 @@

Source: graphs/shortest-path/bellman-ford.js


diff --git a/graphs_shortest-path_dijkstra.js.html b/graphs_shortest-path_dijkstra.js.html index d7237b6e..b522856a 100644 --- a/graphs_shortest-path_dijkstra.js.html +++ b/graphs_shortest-path_dijkstra.js.html @@ -146,7 +146,8 @@

Source: graphs/shortest-path/dijkstra.js

exports.dijkstra = dijkstra; -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -156,13 +157,13 @@

Source: graphs/shortest-path/dijkstra.js


diff --git a/graphs_shortest-path_floyd-warshall.js.html b/graphs_shortest-path_floyd-warshall.js.html index 7eba981d..6fb2a951 100644 --- a/graphs_shortest-path_floyd-warshall.js.html +++ b/graphs_shortest-path_floyd-warshall.js.html @@ -120,13 +120,13 @@

Source: graphs/shortest-path/floyd-warshall.js


diff --git a/graphs_spanning-trees_prim.js.html b/graphs_spanning-trees_prim.js.html index 7d7d9acb..c642970a 100644 --- a/graphs_spanning-trees_prim.js.html +++ b/graphs_spanning-trees_prim.js.html @@ -205,7 +205,8 @@

Source: graphs/spanning-trees/prim.js

}()); -})(typeof window === 'undefined' ? module.exports : window); +})(typeof window === 'undefined' ? module.exports : window); + @@ -215,13 +216,13 @@

Source: graphs/spanning-trees/prim.js


diff --git a/index.html b/index.html index 0d5c7271..cdb882ae 100644 --- a/index.html +++ b/index.html @@ -77,13 +77,13 @@

License

The code in this repository is distributed under the terms of


diff --git a/module-data-structures_binary-search-tree.BinaryTree.html b/module-data-structures_binary-search-tree.BinaryTree.html index 1786fb1d..31ef83d8 100644 --- a/module-data-structures_binary-search-tree.BinaryTree.html +++ b/module-data-structures_binary-search-tree.BinaryTree.html @@ -1620,13 +1620,13 @@
Returns:

diff --git a/module-data-structures_binary-search-tree.Node.html b/module-data-structures_binary-search-tree.Node.html index 1a970c58..dcb84bfd 100644 --- a/module-data-structures_binary-search-tree.Node.html +++ b/module-data-structures_binary-search-tree.Node.html @@ -348,13 +348,13 @@
Type:

diff --git a/module-data-structures_binary-search-tree.html b/module-data-structures_binary-search-tree.html index 2bff7e02..dd8dbf0a 100644 --- a/module-data-structures_binary-search-tree.html +++ b/module-data-structures_binary-search-tree.html @@ -176,13 +176,13 @@

Classes


diff --git a/module-data-structures_heap.Heap.html b/module-data-structures_heap.Heap.html index 7002b2c8..c1f42ce5 100644 --- a/module-data-structures_heap.Heap.html +++ b/module-data-structures_heap.Heap.html @@ -996,13 +996,13 @@
Parameters:

diff --git a/module-data-structures_heap.html b/module-data-structures_heap.html index 76ef5fa0..47abe063 100644 --- a/module-data-structures_heap.html +++ b/module-data-structures_heap.html @@ -188,13 +188,13 @@

Classes


diff --git a/module-data-structures_interval-tree.IntervalTree.html b/module-data-structures_interval-tree.IntervalTree.html index 9c321d66..d97d05d0 100644 --- a/module-data-structures_interval-tree.IntervalTree.html +++ b/module-data-structures_interval-tree.IntervalTree.html @@ -1055,13 +1055,13 @@
Parameters:

diff --git a/module-data-structures_interval-tree.Node.html b/module-data-structures_interval-tree.Node.html index 7e43529a..996d3554 100644 --- a/module-data-structures_interval-tree.Node.html +++ b/module-data-structures_interval-tree.Node.html @@ -634,13 +634,13 @@
Type:

diff --git a/module-data-structures_interval-tree.html b/module-data-structures_interval-tree.html index 183a5505..085337ed 100644 --- a/module-data-structures_interval-tree.html +++ b/module-data-structures_interval-tree.html @@ -170,13 +170,13 @@

Classes


diff --git a/module-data-structures_linked-list.LinkedList.html b/module-data-structures_linked-list.LinkedList.html index 941f2969..1948219c 100644 --- a/module-data-structures_linked-list.LinkedList.html +++ b/module-data-structures_linked-list.LinkedList.html @@ -1011,13 +1011,13 @@
Parameters:

diff --git a/module-data-structures_linked-list.Node.html b/module-data-structures_linked-list.Node.html index 44b70123..c804965d 100644 --- a/module-data-structures_linked-list.Node.html +++ b/module-data-structures_linked-list.Node.html @@ -421,13 +421,13 @@
Type:

diff --git a/module-data-structures_linked-list.html b/module-data-structures_linked-list.html index 16ea3a38..362566ba 100644 --- a/module-data-structures_linked-list.html +++ b/module-data-structures_linked-list.html @@ -185,13 +185,13 @@

Classes


diff --git a/module-data-structures_red-black-tree.RBTree.html b/module-data-structures_red-black-tree.RBTree.html index 31822379..ac6f5747 100644 --- a/module-data-structures_red-black-tree.RBTree.html +++ b/module-data-structures_red-black-tree.RBTree.html @@ -464,13 +464,13 @@
Parameters:

diff --git a/module-data-structures_red-black-tree.html b/module-data-structures_red-black-tree.html index 7b64c315..36f3d64e 100644 --- a/module-data-structures_red-black-tree.html +++ b/module-data-structures_red-black-tree.html @@ -177,13 +177,13 @@

Classes


diff --git a/module-graphs_others_topological-sort.html b/module-graphs_others_topological-sort.html index f2ee24a7..8f3c0f86 100644 --- a/module-graphs_others_topological-sort.html +++ b/module-graphs_others_topological-sort.html @@ -230,13 +230,13 @@
Example

diff --git a/module-graphs_searching_bfs.html b/module-graphs_searching_bfs.html index 68eb1acd..bc0c6fcf 100644 --- a/module-graphs_searching_bfs.html +++ b/module-graphs_searching_bfs.html @@ -274,13 +274,13 @@
Example

diff --git a/module-graphs_searching_dfs.html b/module-graphs_searching_dfs.html index 535e0636..cd7a7f8a 100644 --- a/module-graphs_searching_dfs.html +++ b/module-graphs_searching_dfs.html @@ -274,13 +274,13 @@
Example

diff --git a/module-graphs_shortest-path_bellman-ford.Edge.html b/module-graphs_shortest-path_bellman-ford.Edge.html index 7d2f5edb..67629004 100644 --- a/module-graphs_shortest-path_bellman-ford.Edge.html +++ b/module-graphs_shortest-path_bellman-ford.Edge.html @@ -247,13 +247,13 @@
Parameters:

diff --git a/module-graphs_shortest-path_bellman-ford.html b/module-graphs_shortest-path_bellman-ford.html index d2cfc9bd..e651e350 100644 --- a/module-graphs_shortest-path_bellman-ford.html +++ b/module-graphs_shortest-path_bellman-ford.html @@ -384,13 +384,13 @@
Returns:

diff --git a/module-graphs_shortest-path_dijkstra.html b/module-graphs_shortest-path_dijkstra.html index 3f4897a1..e5dc2a9a 100644 --- a/module-graphs_shortest-path_dijkstra.html +++ b/module-graphs_shortest-path_dijkstra.html @@ -280,13 +280,13 @@
Example

diff --git a/module-graphs_shortest-path_floyd-warshall.html b/module-graphs_shortest-path_floyd-warshall.html index 2aadc117..4df4e4dd 100644 --- a/module-graphs_shortest-path_floyd-warshall.html +++ b/module-graphs_shortest-path_floyd-warshall.html @@ -238,13 +238,13 @@
Example

diff --git a/module-graphs_spanning-trees_prim.Edge.html b/module-graphs_spanning-trees_prim.Edge.html index 61f52ae0..fe6aadaa 100644 --- a/module-graphs_spanning-trees_prim.Edge.html +++ b/module-graphs_spanning-trees_prim.Edge.html @@ -247,13 +247,13 @@
Parameters:

diff --git a/module-graphs_spanning-trees_prim.Graph.html b/module-graphs_spanning-trees_prim.Graph.html index c6c8bf1a..17fb767d 100644 --- a/module-graphs_spanning-trees_prim.Graph.html +++ b/module-graphs_spanning-trees_prim.Graph.html @@ -332,13 +332,13 @@
Returns:

diff --git a/module-graphs_spanning-trees_prim.Vertex.html b/module-graphs_spanning-trees_prim.Vertex.html index 3e48dcc8..352d362d 100644 --- a/module-graphs_spanning-trees_prim.Vertex.html +++ b/module-graphs_spanning-trees_prim.Vertex.html @@ -201,13 +201,13 @@
Parameters:

diff --git a/module-graphs_spanning-trees_prim.html b/module-graphs_spanning-trees_prim.html index 26ec4744..69c76502 100644 --- a/module-graphs_spanning-trees_prim.html +++ b/module-graphs_spanning-trees_prim.html @@ -195,13 +195,13 @@

Classes


diff --git a/module-primes.html b/module-primes.html new file mode 100644 index 00000000..042a2305 --- /dev/null +++ b/module-primes.html @@ -0,0 +1,234 @@ + + + + + JSDoc: Module: primes + + + + + + + + + + +
+ +

Module: primes

+ + + + + + +
+ +
+ + + + + +
+ +
+
+ + +
Returns Sieve of Eratosthenes for specified number + +Simple, ancient algorithm for finding all prime numbers up to any given +limit
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
limit + + +Number + + + + algorithm will return list with prime numbers up + to given limit
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ - will return array with all prime numbers up to + provided limit +
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/module-primes_is-prime.html b/module-primes_is-prime.html new file mode 100644 index 00000000..8d3b2bcf --- /dev/null +++ b/module-primes_is-prime.html @@ -0,0 +1,238 @@ + + + + + JSDoc: Module: primes/is-prime + + + + + + + + + + +
+ +

Module: primes/is-prime

+ + + + + + +
+ +
+ + + + + +
+ +
+
+ + +
Advanced (optimised) method for checking if provided number is prime. +For example for number 104743 it should return true, for 104744 - false.
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
number + + +Number + + + + Number that we check on prime
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Will return true if provided number is prime +
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + +
Example
+ +
var isPrime = require('path/to/primes/is-prime').isPrime;
+
+console.log(isPrime(7)); // true
+console.log(isPrime(18)); // false
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/module-primes_prime-factor-tree.html b/module-primes_prime-factor-tree.html new file mode 100644 index 00000000..888e7033 --- /dev/null +++ b/module-primes_prime-factor-tree.html @@ -0,0 +1,240 @@ + + + + + JSDoc: Module: primes/prime-factor-tree + + + + + + + + + + +
+ +

Module: primes/prime-factor-tree

+ + + + + + +
+ +
+ + + + + +
+ +
+
+ + +
Method will return list of all primes for provided number. +For example for number 18 it should return following list of primes +[2, 3, 3].
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
number + + +Number + + + + Number for which method will find all primes
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ List of available primes for provided number +
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + +
Example
+ +
var primeFactorTree = require('path/to/primes/prime-factor-tree')
+.primeFactorTree;
+
+console.log(primeFactorTree(18)); // [2, 3, 3]
+console.log(primeFactorTree(600851475143)); // [71, 839, 1471, 6857]
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/module-primes_sieve-of-eratosthenes.html b/module-primes_sieve-of-eratosthenes.html new file mode 100644 index 00000000..8f75e418 --- /dev/null +++ b/module-primes_sieve-of-eratosthenes.html @@ -0,0 +1,246 @@ + + + + + JSDoc: Module: primes/sieve-of-eratosthenes + + + + + + + + + + +
+ +

Module: primes/sieve-of-eratosthenes

+ + + + + + +
+ +
+ + + + + +
+ +
+
+ + +
Sieve of Eratosthenes. + +Simple, ancient algorithm for finding all prime numbers up to given limit. + +Returns list of primes up to specified limit. + +For example, for limit 10 it should return following list of primes: +[2, 3, 5, 7]
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
limit + + +Number + + + + Algorithm will returns list of primes up to +specified limit
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Will return list with all prime numbers up to provided +limit +
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + +
Example
+ +
var sieveOfEratosthenes = require('path/to/primes/sieve-of-eratosthenes')
+.sieveOfEratosthenes;
+
+console.log(sieveOfEratosthenes(12)); // [2, 3, 5, 7, 11]
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/primes_is-prime.js.html b/primes_is-prime.js.html new file mode 100644 index 00000000..9cff37d0 --- /dev/null +++ b/primes_is-prime.js.html @@ -0,0 +1,112 @@ + + + + + JSDoc: Source: primes/is-prime.js + + + + + + + + + + +
+ +

Source: primes/is-prime.js

+ + + + + + +
+
+
(function (exports) {
+  'use strict';
+
+  /**
+   * Advanced (optimised) method for checking if provided number is prime.
+   * For example for number 104743 it should return true, for 104744 - false.
+   *
+   * @module primes/is-prime
+   * @param {Number} number - Number that we check on prime
+   * @returns {Boolean} Will return true if provided number is prime
+   *
+   * @example
+   * var isPrime = require('path/to/primes/is-prime').isPrime;
+   *
+   * console.log(isPrime(7)); // true
+   * console.log(isPrime(18)); // false
+   */
+  exports.isPrime = function (number) {
+    if (number === 1) {
+      return false;
+
+    } else if (number < 4) {
+      /**
+       * 2 and 3 are prime
+       */
+      return true;
+
+    } else if (number % 2 === 0) {
+      return false;
+
+    } else if (number < 9) {
+      /**
+       * We have already excluded 4,6 and 8
+       */
+      return true;
+
+    } else if (number % 3 === 0) {
+      return false;
+
+    } else {
+      /**
+       * 'number' rounded to the greatest integer 'rounded' so that:
+       * rounded * rounded <= number
+       */
+      var rounded = Math.floor(Math.sqrt(number)),
+        factor = 5;
+      while (factor <= rounded) {
+        if (number % factor === 0) {
+          return false;
+        }
+        if (number % (factor + 2) === 0) {
+          return false;
+        }
+        factor += 6;
+      }
+    }
+
+    return true;
+  };
+
+}(typeof exports === 'undefined' ? window : exports));
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/primes_prime-factor-tree.js.html b/primes_prime-factor-tree.js.html new file mode 100644 index 00000000..6fd55ec2 --- /dev/null +++ b/primes_prime-factor-tree.js.html @@ -0,0 +1,88 @@ + + + + + JSDoc: Source: primes/prime-factor-tree.js + + + + + + + + + + +
+ +

Source: primes/prime-factor-tree.js

+ + + + + + +
+
+
(function (exports) {
+  'use strict';
+
+  /**
+   * Method will return list of all primes for provided number.
+   * For example for number 18 it should return following list of primes
+   * [2, 3, 3].
+   *
+   * @module primes/prime-factor-tree
+   * @param {Number} number - Number for which method will find all primes
+   * @returns {Array} List of available primes for provided number
+   *
+   * @example
+   * var primeFactorTree = require('path/to/primes/prime-factor-tree')
+   * .primeFactorTree;
+   *
+   * console.log(primeFactorTree(18)); // [2, 3, 3]
+   * console.log(primeFactorTree(600851475143)); // [71, 839, 1471, 6857]
+   */
+  exports.primeFactorTree = function (number) {
+    var div = 2,
+      array = [];
+
+    while (number > 1) {
+      if (number % div === 0) {
+        number /= div;
+
+        array.push(div);
+      } else {
+        div += 1;
+      }
+    }
+
+    return array;
+  };
+
+}(typeof exports === 'undefined' ? window : exports));
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/primes_sieve-of-eratosthenes.js.html b/primes_sieve-of-eratosthenes.js.html new file mode 100644 index 00000000..daac6787 --- /dev/null +++ b/primes_sieve-of-eratosthenes.js.html @@ -0,0 +1,106 @@ + + + + + JSDoc: Source: primes/sieve-of-eratosthenes.js + + + + + + + + + + +
+ +

Source: primes/sieve-of-eratosthenes.js

+ + + + + + +
+
+
(function (exports) {
+  'use strict';
+
+  /**
+   * Sieve of Eratosthenes.
+   *
+   * Simple, ancient algorithm for finding all prime numbers up to given limit.
+   *
+   * Returns list of primes up to specified limit.
+   *
+   * For example, for limit 10 it should return following list of primes:
+   * [2, 3, 5, 7]
+   *
+   * @module primes/sieve-of-eratosthenes
+   * @param {Number} limit - Algorithm will returns list of primes up to
+   * specified limit
+   * @returns {Array} Will return list with all prime numbers up to provided
+   * limit
+   *
+   * @example
+   * var sieveOfEratosthenes = require('path/to/primes/sieve-of-eratosthenes')
+   * .sieveOfEratosthenes;
+   *
+   * console.log(sieveOfEratosthenes(12)); // [2, 3, 5, 7, 11]
+   */
+  exports.sieveOfEratosthenes = function (limit) {
+    var sieve = [],
+      primes = [], k, l;
+
+    sieve[1] = false;
+
+    for (k = 2; k <= limit; k += 1) {
+      sieve[k] = true;
+    }
+
+    for (k = 2; k * k <= limit; k += 1) {
+      if (sieve[k] !== true) {
+        continue;
+      }
+
+      for (l = k * k; l <= limit; l += k) {
+        sieve[l] = false;
+      }
+    }
+
+    sieve.forEach(function (value, key) {
+      if (value) {
+        this.push(key);
+      }
+    }, primes);
+
+    return primes;
+  };
+
+}(typeof exports === 'undefined' ? window : exports));
+
+
+
+ + + + +
+ + + +
+ + + + + + +