Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9946c1

Browse files
committed
Fix btPowerSet() comments.
1 parentda0f97a commitd9946c1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

‎src/algorithms/sets/power-set/btPowerSet.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66
*@return {*[][]} - All subsets of original set.
77
*/
88
functionbtPowerSetRecursive(originalSet,allSubsets=[[]],currentSubSet=[],startAt=0){
9-
//In order to avoid duplication we need to start from next element every time we're forming a
10-
//subset. If we will start from zero then we'll have duplicates like {3, 3, 3}.
9+
//Let's iterate over originalSet elements that may be added to the subset
10+
//without having duplicates. The value of startAt prevents adding the duplicates.
1111
for(letposition=startAt;position<originalSet.length;position+=1){
12-
// Let's push current element to the subset.
12+
// Let's push current element to the subset
1313
currentSubSet.push(originalSet[position]);
14+
1415
// Current subset is already valid so let's memorize it.
16+
// We do array destruction here to save the clone of the currentSubSet.
17+
// We need to save a clone since the original currentSubSet is going to be
18+
// mutated in further recursive calls.
1519
allSubsets.push([...currentSubSet]);
16-
// Let's try to form all other subsets for the current subset.
20+
21+
// Let's try to generate all other subsets for the current subset.
22+
// We're increasing the position by one to avoid duplicates in subset.
1723
btPowerSetRecursive(originalSet,allSubsets,currentSubSet,position+1);
18-
// BACKTRACK. Exclude last element from the subset and try the next one.
24+
25+
// BACKTRACK. Exclude last element from the subset and try the next valid one.
1926
currentSubSet.pop();
2027
}
2128

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp