Skip to content

Commit 5e65120

Browse files
fix token method and added powerset method
1 parent 7e6a772 commit 5e65120

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
[![Windows Build][appveyor-image]][appveyor-url]
3131
[![Test Coverage][coveralls-image]][coveralls-url]
3232

33-
[npm-image]: https://img.shields.io/badge/npm-v3.30.15-blue
33+
[npm-image]: https://img.shields.io/badge/npm-v3.31.15-blue
3434
[npm-url]: https://www.npmjs.com/package/solverjs
3535
[downloads-image]: https://img.shields.io/badge/Downloads-200%2FWeeks-green
3636
[downloads-url]: https://www.npmjs.com/package/solverjs
@@ -383,6 +383,12 @@ The min method returns the minimum value from the given array.
383383
console.log(solverjs.min([2, 5, 6, 3]));
384384
// The output is : 2
385385

386+
### getPowerset
387+
In mathematics, the power set (or powerset) of a set S is the set of all subsets of S, including the empty set and S itself.
388+
389+
console.log(solverjs.getPowerset([1, 2, 3]));
390+
// The output is : [[], [ 1 ], [ 2 ], [ 1, 2 ], [ 3 ], [ 1, 3 ], [ 2, 3 ], [ 1, 2, 3 ]]
391+
386392
## Number System Conversion
387393
We all know we have very frequently is number system conversion in programming, our number system conversion methods provide all type of conversion of the numbers systems.
388394

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ let {
220220
remainder,
221221
isFibonacci,
222222
max,
223-
min
223+
min,
224+
getPowerset
224225
} = require('./src/math/math');
225226

226227
// numbers systems.
@@ -581,6 +582,7 @@ module.exports = {
581582
isFibonacci,
582583
max,
583584
min,
585+
getPowerset,
584586
// numbers system.
585587
hexToDec,
586588
hexToOct,

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solverjs",
3-
"version": "3.30.15",
3+
"version": "3.31.15",
44
"description": "This package is a combination of many useful functions.",
55
"main": "index.js",
66
"scripts": {
@@ -40,6 +40,7 @@
4040
"lcm",
4141
"hcf",
4242
"ascii",
43+
"getPowerset",
4344
"reverse",
4445
"isPalindrome",
4546
"permutation",

src/math/math.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ let isTitle = (str) => /^([A-Z][a-z]+)$/.test(str);
433433

434434
// unique token generator, generate a unique token.
435435
/**
436-
* Fenerate a unique token, every time you run without any arguments.
436+
* The token method generates and returns a unique token in string format, every time you run without any arguments.
437437
* @returns return a unique token every time to run.
438438
*/
439439
let token = () => {
@@ -514,6 +514,24 @@ let max = (arr) => {
514514
return mn;
515515
}
516516

517+
/**
518+
* The getPowerset method calculates all subset of the given set and return it, also known as powerset.
519+
* @param {Array} set A set array.
520+
* @returns {Array[][]} `Powerset` Returns the powerset of the given set.
521+
*/
522+
function getPowerset(set) {
523+
let subset = [[]];
524+
525+
for(let ele of set) {
526+
let len = subset.length;
527+
for(let i = 0; i < len; i++) {
528+
subset.push([...subset[i], ele]);
529+
}
530+
}
531+
532+
return subset;
533+
}
534+
517535
// export maths methods.
518536
module.exports = {
519537
getFib,
@@ -555,5 +573,6 @@ module.exports = {
555573
remainder,
556574
isFibonacci,
557575
max,
558-
min
576+
min,
577+
getPowerset
559578
}

0 commit comments

Comments
 (0)