

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find all subsets of a set in JavaScript?
To find all subsets of a set, use reduce() along with map() in JavaScript. Let’s say, we are passing the set [8,9] and finding the subsets.
Example
const findAllSubsetsoOfGivenSet = originalArrayValue => originalArrayValue.reduce( (givenSet, setValue) => givenSet.concat( givenSet.map(givenSet => [setValue,...givenSet]) ), [[]] ); console.log(findAllSubsetsoOfGivenSet([8,9]));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo36.js.
Output
This will produce the following output.
PS C:\Users\Amit\JavaScript-code> node demo36.js [ [], [ 8 ], [ 9 ], [ 9, 8 ] ]
- Related Questions & Answers
- Find all distinct subsets of a given set in C++
- Print all subsets of given size of a set in C++
- Java Program To Find all the Subsets of a String
- Python program to get all subsets of given size of a set
- Python program to get all subsets of a given size of a set
- Finding all possible subsets of an array in JavaScript
- Sum of all subsets of a set formed by first n natural numbers
- C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
- C++ Program to Generate All Pairs of Subsets Whose Union Make the Set
- Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers
- Find all disjointed intersections in a set of vertical line segments in JavaScript
- Sum of XOR of all possible subsets in C++
- Sum of the products of all possible Subsets in C++
- Count number of ways to partition a set into k subsets in C++
- How to remove all the elements from a set in javascript?
Advertisements